extensible and flexible php cache lib.
composer require silmaralberti/php-cache
// set redis adapter connection
$redisConnectionParams = [
'host' => 'host.docker.internal'
];
$serializer = new IgBinaryLib();
$redisAdapter = new RedisAdapter($redisConnectionParams);
$hash = new HashKeyLib();
$testSettings = new PhpCacheSettingsModel(
$redisAdapter,
$serializer,
$hash
);
$phpCache = new PhpCache($testSettings);
$queryContent = [
'keyA' => 'keyContentA',
'keyB' => 'keyContentB'
];
$valueContent = [
'valueA' => 'contentA',
'valueB' => 'contentB'
];
$valueCount = $phpCache->increase($queryContent, 1);
// $valueCount 1 if first call
$successOnSave = $phpCache->set($queryContent, $valueContent);
// $successOnSave true if success else false
$cachedValueContent = $phpCache->get($queryContent);
// false if not found in cache
// $cachedValueContent is equal $valueContent
IgBinaryLib
DefaultSerializerLib
RedisAdapter
HashKeyLib
increment and return key value
load cache data
storage cache data
get response of function from cache or call function and store result on cache
example:
$serializer = new IgBinaryLib();
$redisAdapter = new RedisAdapter($redisConnectionParams);
$hash = new HashKeyLib();
$testSettings = new PhpCacheSettingsModel(
$redisAdapter,
$serializer,
$hash
);
$phpCache = new PhpCache($testSettings);
$testValue = 'storedOnCacheValue';
$result = $phpCache->cacheFunction(
function ($testValue) {
return $testValue;
},
[$testValue],
'functionExample'
);
echo $result;
// print 'storedOnCacheValue';