marvin255 / in-memory-cache
Array based cache for PHP
v3.0.3
2026-04-03 20:54 UTC
Requires
- php: >=8.3
- psr/clock: ^1.0
- psr/simple-cache: ^3.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- infection/infection: ^0.32
- phpunit/phpunit: ^12.0|^13.0
- vimeo/psalm: ^6.0
This package is auto-updated.
Last update: 2026-04-03 20:55:20 UTC
README
Simple PSR-16 implementation that uses an 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
The decorator allows you to use two caches at the same time. All data from the base cache (e.g. a Redis-based cache) will also be stored in InMemoryCache. This decorator can reduce the number of requests for long-running 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 call will trigger a request to Redis and save the data to memory $decorator->get('test'); // this call won't trigger any requests and will just return data from memory