PHP library to deal with fast and simple cache solutions with multiple adapter options.
composer require php-library/simple-cache
Detailed examples can be found in "examples/" directory
In order to create a SimpleCache instance, we need Adapter instance.
Make sure your storagePath exists and accessible.
$fileAdapter = new FileAdapter($storagePath);
$fileBasedStorage = new SimpleCache($fileAdapter);
$fileBasedStorage->save('testKey', 'test value');
$valueFromFileBased = $fileBasedStorage->retrieve('testKey');
printf($valueFromFileBased);
Above code will print "test value".
Redis Adapter expects 4 parameter which are:
- host
- port
- databaseId
- timeout
$redisAdapter = new RedisAdapter($redisHost, $redisPort, $redisDatabaseId, $redisTimeout);
$redisBasedStorage = new SimpleCache($redisAdapter);
$redisBasedStorage->save('somekey', 'somevalue');
$result = $redisBasedStorage->retrieve('somekey');
In order to create a Memcahce SimpleCache instance we need to pass Memcache Instance to Adapter.
$memcacheInstance= new Memcached();
$memcacheInstance->addServer('localhost', 11211);
$memcachedBasedStorage = new SimpleCache(new MemcachedAdapter($memcacheInstance));
$result = $memcachedBasedStorage->save('testKeyInMemcached', 'test value in memcached');
$valueFromMemcachedBased = $memcachedBasedStorage->retrieve('testKeyInMemcached');