Soupmix Cache provides framework agnostic implementation of PSR-16 Simple Cache Interface.
It's recommended that you use Composer to install Soupmix Cache Adaptors.
$ composer require soupmix/cache-redis "~0.3"require_once '/path/to/composer/vendor/autoload.php';
$rConfig = ['host'=> "127.0.0.1"];
$handler = new Redis();
$handler->connect(
$rConfig['host']
);
$cache = new Soupmix\Cache\RedisCache($handler);$ composer require soupmix/cache-memcached "~0.3"require_once '/path/to/composer/vendor/autoload.php';
$config = [
'bucket' => 'test',
'hosts' => ['127.0.0.1'],
;
$handler = new Memcached($config['bucket']);
$handler->setOption(Memcached::OPT_LIBKETAMA_COMPATIBLE, true);
$handler->setOption(Memcached::OPT_BINARY_PROTOCOL, true);
if (!count($handler->getServerList())) {
$hosts = [];
foreach ($config['hosts'] as $host) {
$hosts[] = [$host, 11211];
}
$handler->addServers($hosts);
}
$cache = new Soupmix\Cache\MemcachedCache($handler);$ composer require soupmix/cache-apcu "~0.2"require_once '/path/to/composer/vendor/autoload.php';
$cache = new Soupmix\Cache\APCUCache();$cache->set($key, $value, $ttl);@param string $key: The key of the item to store
@param mixed $value: The value of the item to store
@param null|integer|DateInterval $ttl: Optional. The TTL value of this item. If no value is sent and the driver supports TTL then the library may set a default value for it or let the driver take care of that. Predefined DataIntervals: TTL_MINUTE, TTL_HOUR, TTL_DAY.
@return bool True on success and false on failure
$cache->set('my_key, 'my_value', TTL_DAY);
// returns bool(true)$cache->has($key);@param string $key: The unique cache key of the item to delete
@return bool True on success and false on failure
$cache->has('my_key');
// returns bool(true)$cache->get($key, default=null);@param string $key: The unique key of this item in the cache @return mixed The value of the item from the cache, or null in case of cache miss
$cache->get('my_key');
// returns string(8) "my_value"$cache->delete($key);@param string $key: The unique cache key of the item to delete
@return bool True on success and false on failure
$cache->delete('my_key');
// returns bool(true)$cache->setMultiple(array $items);@param array|Traversable $items: An array of key => value pairs for a multiple-set operation.
@param null|integer|DateInterval $ttl: Optional. The amount of seconds from the current time that the item will exist in the cache for. If this is null then the cache backend will fall back to its own default behaviour.
@return bool True on success and false on failure
$items = ['my_key_1'=>'my_value_1', 'my_key_2'=>'my_value_2'];
$cache->setMultiple($items);
// returns bool(true)$cache->getMultiple($keys, $default=null);@param array|Traversable $keys: A list of keys that can obtained in a single operation.
@return array An array of key => value pairs. Cache keys that do not exist or are stale will have a value of null.
$keys = ['my_key_1', 'my_key_2'];
$cache->getMultiple($keys);
/*
returns array(2) {
["my_key_1"]=>
string(3) "my_value_1"
["my_key_2"]=>
string(3) "my_value_2"
}
*/$cache->deleteMultiple($keys);@param array|Traversable $keys: The array of string-based keys to be deleted
@return bool True on success and false on failure
$keys = ['my_key_1', 'my_key_2'];
$cache->deleteMultiple($keys);
/*
returns array(2) {
["my_key_1"]=>
bool(true)
["my_key_2"]=>
bool(true)
}
*/$cache->increment($key, $step);@param string $key: The cache item key
@param integer $step: The value to increment by, defaulting to 1
@return int|bool The new value on success and false on failure
$cache->increment('counter', 1);
// returns int(1)
$cache->increment('counter', 1);
// returns int(2)Memcached does not increments the keys that's not been set before. For Memcached you must set key with the default value.
$cache->set('counter', 0);
// returns bool(true)
$cache->increment('counter', 1);
// returns int(1)$cache->decrement($key, $step);@param string $key: The cache item key
@param integer $step: The value to decrement by, defaulting to 1
$cache->decrement('counter', 1);
// returns int(1)
$cache->decrement('counter', 1);
// returns int(0)Memcached does not decrements the keys that's not been set before. For Memcached you must set key with the default value.
$cache->set('counter', 1);
// returns bool(true)
$cache->decrement('counter', 1);
// returns int(0)Memcached does not decrements to negative values and stops at zero where Redis can decrement to negative values and goes setting -1,-2, etc...
@return bool True on success and false on failure
$cache->clear();
// returns bool(true)