super-simple / cache
The PHP cache library implementing psr-16.
Installs: 4
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/super-simple/cache
Requires
- php: ^8.4
- psr/simple-cache: ^1.0
Requires (Dev)
- phpunit/phpunit: ^11.5
README
A simple cache library implementing PSR-16.
Install
composer require super-simple/cache
Requires PHP 8.4 or newer.
Usage
Basic usage:
<?php require_once __DIR__ . '/../vendor/autoload.php'; use SSCache\Cache; $cacheService = new Cache(new YourStorage()); // Adding a Serializer. // The CacheSerializeDelegator uses default php serializer. // For better performance could be added msgpack or igbinary. $cacheSerializer = new CacheSerializeDelegator($cache); // A CackeKeyDelegator must be the last one to handle key validation first $cache = new CacheKeyDlelegator($cacheSerializer); // Set the value $cache->set($key, $value, $ttl); // Get the value $result = $cache->get($key);
The $ttl could be int, null or \DateInterval
The storage must implement SSCache\CacheStorageInterface.
It's up to you how to handle $ttl in the storage.
If better performance is need it then install extensions (msgpack or igbinary) and implement serialize functions. A serializer must implement CacheSerializable or just extends the AbstractCacheSerializer.
Extra behavior could be added using a Delegator which extends AbstractCacheDelegator.