This is a simple Cache Abstraction Layer for PHP >= 5.3 that provides a simple interaction with your cache-server. You can define the Adapter / Serializer in the "constructor" or the class will auto-detect you server-cache in this order:
- Memcached / Memcache
- Redis
- Xcache
- APC / APCu
- static array
##Get "Simple Cache" You can download it from here, or require it using composer.
{
"require": {
"voku/simple-cache": "2.*",
"predis/predis": "1.*"
}
}
##Install via "composer require"
composer require voku/simple-cache
##Quick Start
require_once 'composer/autoload.php';
$cache = new \voku\cache\Cache();
// example
// $cache = \voku\cache\Cache();
// $cache->setItem('foo', 'bar');
// $bar = $cache->getItem('foo');
##Usage
function test() {
$cache = \voku\cache\Cache();
if (
$cache->getCacheIsReady() === true
&&
$cache->existsItem('foo')
) {
return $cache->getItem('foo');
} else {
$bar = someSpecialFunctionsWithAReturnValue();
$cache->setItem('foo', $bar);
return $bar;
}
##No-Cache for the admin or a specific ip-address
If you use the parameter "$checkForUser" (true) from the constructor, then the cache isn't used for the admin-session. You can also overwrite the check for the user, if you add a global function named "checkForDev()".