perf / caching
This package is abandoned and no longer maintained.
The author suggests using the jmf/simple-cache package instead.
Allows to store data with caching engines (Memcache, file system, etc).
3.1.1
2021-09-11 02:35 UTC
Requires
- php: >=7.4
- perf/timing: ^2.0
Requires (Dev)
- ext-xdebug: *
- pdepend/pdepend: ^2.10
- phing/phing: ^2.17
- phpmd/phpmd: ^2.10
- phpunit/phpunit: ^9.5
- squizlabs/php_codesniffer: ^3.6
Suggests
- ext-memcached: Memcached storage
README
Allows caching of data (with Memcached, file-system, etc).
Usage
Initialization
<?php use perf\Caching\CacheClient; use perf\Caching\Storage\FileSystemCachingStorage; use perf\Caching\Storage\MemcachedCachingStorage; use perf\Caching\Storage\NullCachingStorage; use perf\Caching\Storage\VolatileCachingStorage; // Memcached $storage = MemcachedCachingStorage::createFromCredentials('1.2.3.4', 123); $cache = CacheClient::createWithStorage($storage); // Volatile storage $storage = new VolatileCachingStorage(); $cache = CacheClient::createWithStorage($storage); // File-system storage $storage = new FileSystemCachingStorage('/tmp/cache'); $cache = CacheClient::createWithStorage($storage); // Null storage (caches nothing) $storage = new NullCachingStorage(); $cache = CacheClient::createWithStorage($storage);
Storing and retrieving data
<?php $objectToStore = new \stdClass(); $objectToStore->bar = 'baz'; $cache->store('foo', $objectToStore); // ... $object = $cache->tryFetch('foo');