marvin255 / in-memory-cache
Array based cache for PHP
v2.3.3
2024-12-01 15:46 UTC
Requires
- php: >=8.1
- psr/clock: ^1.0
- psr/simple-cache: ^3.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- infection/infection: ^0.27.0
- phpunit/phpunit: ^10.0
- vimeo/psalm: ^5.0
This package is auto-updated.
Last update: 2024-12-01 15:53:25 UTC
README
Simple PSR-16 implementation which uses internal array to store data.
Usage
use Marvin255\InMemoryCache\InMemoryCache; $maxCacheSize = 10000; // only 10000 can be stored by this object $defaultTTL = 60; // 60 seconds as default TTL $cache = new InMemoryCache($maxCacheSize, $defaultTTL);
Decorator
Decorator allows to use two caches in the same time. All data from basic cache (e.g. redis based cache) will be also stored in InMemoryCache. This decorator can reduce requests amount for long-living php processes.
use Marvin255\InMemoryCache\InMemoryCache; use Marvin255\InMemoryCache\CompositeCache; $maxCacheSize = 10000; // only 10000 can be stored by this object $defaultTTL = 60; // 60 seconds as default TTL $inMemoryCache = new InMemoryCache($maxCacheSize, $defaultTTL); $redisCache = new MyAwesomeRedisCache(); $decorator = new CompositeCache($inMemoryCache, $redisCache); $decorator->get('test'); // this get will trigger a request to redis and save data to memory $decorator->get('test'); // this get won't trigger any requests and just return data from memory