jmf /simple-cache
实现PSR-16简单缓存接口的缓存包。
1.0.0
2024-05-20 02:23 UTC
Requires
- php: >=8.3
- psr/clock: ^1.0
- psr/log: ^3.0
- psr/simple-cache: ^3.0
- webmozart/assert: ^1.11
Requires (Dev)
- phing/phing: ^2.17
- phpmd/phpmd: ^2.13
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^11.1
- rector/rector: ^1.0
- squizlabs/php_codesniffer: ^3.8
Suggests
- ext-memcached: *
- jmf/time: ^1.0
Provides
README
允许缓存数据(与Memcached、文件系统等一起使用)。
用法
初始化
<?php use Jmf\Cache\CacheClient; use Jmf\Cache\Storage\FileSystemStorage; use Jmf\Cache\Storage\MemcachedStorage; use Jmf\Cache\Storage\NullStorage; use Jmf\Cache\Storage\VolatileStorage; use Psr\Clock\ClockInterface; use Psr\Log\LoggerInterface; /* @var ClockInterface $clock */ /* @var LoggerInterface $logger */ // Memcached $storage = MemcachedStorage::createFromCredentials('123.45.67.89'); $cache = new CacheClient($storage, $clock, $logger); // Volatile storage $storage = new VolatileStorage(); $cache = new CacheClient($storage, $clock, $logger); // File-system storage $storage = new FileSystemStorage('/tmp/cache'); $cache = new CacheClient($storage, $clock, $logger); // Null storage (caches nothing) $storage = new NullStorage(); $cache = new CacheClient($storage, $clock, $logger);
存储和检索数据
<?php $objectToStore = new \stdClass(); $objectToStore->bar = 'baz'; $cache->set('foo', $objectToStore); // ... $object = $cache->get('foo');