chillerlan / php-cache
A psr/simple-cache implementation. PHP 8.1+
Fund package maintenance!
Ko Fi
www.paypal.com/donate?hosted_button_id=WLYUNAT9ZTJZ4
Installs: 74 211
Dependents: 14
Suggesters: 0
Security: 0
Stars: 15
Watchers: 3
Forks: 3
Open Issues: 0
Requires
- php: ^8.1
- chillerlan/php-settings-container: ^3.1
- psr/log: ^1.1 || ^2.0 || ^3.0
- psr/simple-cache: ^2.0 || ^3.0
Requires (Dev)
- phan/phan: ^5.4
- phpmd/phpmd: ^2.15
- phpunit/phpunit: ^10.5
- squizlabs/php_codesniffer: ^3.9
Provides
- psr/simple-cache-implementation: 2.0 || 3.0
README
A psr/simple-cache implementation for PHP 8.1+.
Features:
- PSR-16 simple-cache-implementation
- persistent: File based, Memcached, Redis
- non-persistent: Session, Memory
Requirements
Documentation
Installation using composer
You can simply clone the repo and run composer install
in the root directory.
In case you want to include it elsewhere, just add the following to your composer.json:
(note: replace dev-main
with a version constraint,
e.g. ^4.1
- see releases for valid versions)
{ "require": { "php": "^8.1", "chillerlan/php-cache": "dev-main" } }
Installation via terminal: composer require chillerlan/php-cache
Profit!
Usage
Just invoke a cache instance with the desired CacheInterface
like so:
// Redis $redis = new Redis; $redis->pconnect('127.0.0.1', 6379); $cache = new RedisCache($redis); // Memcached $memcached = new Memcached('myCacheInstance'); $memcached->addServer('localhost', 11211); $cache = new MemcachedCache($memcached); // APCU $cache = new APCUCache; // File $cache = new FileCache(new CacheOptions(['cacheFilestorage' => __DIR__.'/../.cache'])); // Session $cache = new SessionCache(new CacheOptions(['cacheSessionkey' => '_my_session_cache'])); // Memory $cache = new MemoryCache;
Methods
See: Psr\SimpleCache\CacheInterface
$cache->get(string $key, $default = null); // -> mixed $cache->set(string $key, $value, int $ttl = null):bool $cache->delete(string $key):bool $cache->has(string $key):bool $cache->clear():bool $cache->getMultiple(array $keys, $default = null):array // -> mixed[] $cache->setMultiple(array $values, int $ttl = null):bool $cache->deleteMultiple(array $keys):bool
Disclaimer!
I don't take responsibility for molten memory modules, bloated hard disks, self-induced DoS, broken screens etc. Use at your own risk! 🙈