mj-zana / cache
PSR-16 caches (array, file, null) with remember() for Zana applications
v2.37.0
2026-11-21 03:34 UTC
Requires
- php: ^8.5
- mj-zana/core: ^2.4
- psr/simple-cache: ^3.0
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^11.5
Suggests
None
Provides
Conflicts
None
Replaces
None
- dev-main
- v2.37.0
- v2.36.0
- v2.35.0
- v2.34.0
- v2.33.0
- v2.32.0
- v2.31.0
- v2.30.0
- v2.29.0
- v2.28.0
- v2.27.0
- v2.26.0
- v2.25.0
- v2.24.0
- v2.23.0
- v2.22.0
- v2.21.0
- v2.20.0
- v2.19.0
- v2.18.0
- v2.17.0
- v2.16.0
- v2.15.0
- v2.14.0
- v2.13.0
- v2.12.0
- v2.11.0
- v2.10.0
- v2.9.0
- v2.8.0
- v2.7.0
- v2.6.0
- v2.5.0
- v2.4.0
- v2.3.0
- v2.2.0
- v2.1.0
- v2.0.0
- v2.0.0-rc.1
- v2.0.0-beta.3
- v2.0.0-beta.2
- v2.0.0-beta.1
- v2.0.0-alpha.3
This package is auto-updated.
Last update: 2026-11-24 16:52:50 UTC
README
PSR-16 caches with remember() and pull(), and named stores from
configuration. Requires PHP 8.5 or later.
composer require mj-zana/cache
Usage
Register CacheServiceProvider and configure stores in config/cache.php:
return [ 'default' => 'file', 'stores' => [ 'file' => ['driver' => 'file', 'path' => 'var/cache/data', 'ttl' => 3600], 'memory' => ['driver' => 'array'], ], ];
public function __construct(private CacheInterface $cache) {} $report = $this->cache->remember("bmi.report.{$patientId}", 600, fn () => $this->builder->build($patientId)); $this->cache->delete("bmi.report.{$patientId}");
Stores
| Store | Behaviour |
|---|---|
array |
in memory, per process; values are copied through serialize() |
file |
one file per key, written atomically; corrupt or expired files are misses |
null |
stores nothing |
- Keys follow PSR-16: up to 255 characters, without
{}()/\@:. - TTL is seconds or a
DateInterval.nulluses the store's default (forever unless configured), and a TTL ≤ 0 deletes the entry. - Defaults: without configuration, the default store is
array. - Atomic (2.26):
add($key, $value, $ttl)stores only when the key holds nothing and says whether it did;increment($key, $by, $ttl)returns the new count, and an existing count keeps its expiry. Requests at the same instant take turns: the file store locks the key while it reads and writes. Every store implementsAtomicCacheInterface; mj-zana/security's rate limits and single-use tokens rely on it.
License
MIT — see LICENSE.