PHPackages                             superpms/program-cache - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Caching](/categories/caching)
4. /
5. superpms/program-cache

ActiveLibrary[Caching](/categories/caching)

superpms/program-cache
======================

pms cache program

v1.0.x-dev(2mo ago)019Apache-2.0PHPPHP &gt;=8.1

Since May 21Pushed 2mo agoCompare

[ Source](https://github.com/superpms/program-cache)[ Packagist](https://packagist.org/packages/superpms/program-cache)[ RSS](/packages/superpms-program-cache/feed)WikiDiscussions v1.0 Synced 1w ago

READMEChangelogDependencies (1)Versions (1)Used By (0)

superpms/program-cache
======================

[](#superpmsprogram-cache)

`program-cache` 是 superpms 的文件缓存包，提供 `pms\facade\Cache` facade 和 `pms\program\cache\Driver` 文件型缓存实现。

它的职责是把简单 key/value 缓存、抢占式缓存生成和轻量文件锁接入框架运行期；它不是 Redis 包，也不负责业务端缓存策略。

要求
--

[](#要求)

- PHP `>=8.1`
- 依赖 superpms 基础 facade、路径和生命周期能力

安装与挂载
-----

[](#安装与挂载)

```
composer require superpms/program-cache
```

包的 `composer.json` 会通过 `autoload.files` 加载 `bin/autoload.php`，再加载 `bin/autorun.php`。

当框架存在 `pms\hook\LifecycleHook` 时，包会在 `LIFECYCLE_BOOT` 阶段执行：

```
\pms\facade\Cache::init(\pms\facade\Path::getRuntime('cache'));
```

也就是说，默认缓存目录是项目 runtime 下的 `cache` 目录。这个包没有 `resource/config.php`，也不会通过 `extra.pms.config` 投影项目配置文件。

快速使用
----

[](#快速使用)

```
use pms\facade\Cache;

Cache::set('demo:user:1', ['name' => 'Ada'], 300);

$user = Cache::get('demo:user:1', []);

Cache::delete('demo:user:1');
```

抢占式生成缓存：

```
$data = Cache::setnxCache('report:daily', function (callable $setExpire) {
    $setExpire(600);
    return build_daily_report();
});
```

简单文件锁：

```
Cache::lock('sync-job', 3, 50);

try {
    run_sync_job();
} finally {
    Cache::unlock('sync-job');
}
```

主要模块
----

[](#主要模块)

- `bin/autoload.php`: Composer files autoload 入口
- `bin/autorun.php`: 生命周期挂载入口
- `src/pms/facade/Cache.php`: facade 入口
- `src/pms/program/cache/Driver.php`: 文件缓存 driver

Docs 导航
-------

[](#docs-导航)

- [文档入口](docs/README.md)
- [快速接入](docs/guide/quick-start.md)
- [API 参考](docs/reference/api.md)
- [运行流程](docs/internals/runtime-flow.md)
- [实现注意事项](docs/internals/implementation-notes.md)

注意事项
----

[](#注意事项)

- 缓存文件名是 `md5($key)`，不会保留原始 key。
- 缓存值通过 `serialize([value, expire])` 写入文件。
- `get()` 遇到文件不存在、读取失败、反序列化失败或过期时返回默认值。
- `exists()`、`setnx()` 和 `setnxCache()` 会把 `empty()` 结果视作不存在；缓存 `0`、`false`、空字符串、空数组时要特别注意。
- 过期缓存读取时不会自动删除文件。
- `setnxCache()` 等待超时会抛出 `RedisException`，虽然当前实现是文件缓存。

###  Health Score

31

—

LowBetter than 65% of packages

Maintenance83

Actively maintained with recent releases

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity26

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

89d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/be4f8ca688945fc17bb53deca1a956f72abfef2bd156e542bf899b0d2b15c08d?d=identicon)[xiyiao](/maintainers/xiyiao)

---

Top Contributors

[![XiyiaoBoss](https://avatars.githubusercontent.com/u/170755009?v=4)](https://github.com/XiyiaoBoss "XiyiaoBoss (9 commits)")

### Embed Badge

![Health badge](/badges/superpms-program-cache/health.svg)

```
[![Health](https://phpackages.com/badges/superpms-program-cache/health.svg)](https://phpackages.com/packages/superpms-program-cache)
```

###  Alternatives

[iazaran/smart-cache

Smart Cache is a caching optimization package designed to enhance the way your Laravel application handles data caching. It intelligently manages large data sets by compressing, chunking, or applying other optimization strategies to keep your application performant and efficient.

21114.2k](/packages/iazaran-smart-cache)[phpfastcache/phpssdb

PHP SSDB Driver for phpFastCache

14736.9k1](/packages/phpfastcache-phpssdb)[rapidwebltd/rw-file-cache

RW File Cache is a PHP File-based Caching Library. Its syntax is designed to closely resemble the PHP memcache extension.

15196.8k7](/packages/rapidwebltd-rw-file-cache)[yuzuru-s/redis-recommend

Wrapping Redis's sorted set APIs for specializing recommending operations.

392.9k](/packages/yuzuru-s-redis-recommend)[ichhabrecht/intcache

Turn uncachable page objects into cacheable links

193.9k](/packages/ichhabrecht-intcache)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
