marvin255/in-memory-cache

Array based cache for PHP

Maintainers

Package info

github.com/marvin255/in-memory-cache

pkg:composer/marvin255/in-memory-cache

Statistics

Installs: 2 064

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 0

v3.0.3 2026-04-03 20:54 UTC

README

Build Status

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