1. Go to this page and download the library: Download skrip42/cachelayer-bundle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
/**
* @Cache(LocalCache::class) //execute first
* @Cache(RedisCache::class) //if LocalCache exist value, RedisCache will not be called
*/
public function foo(...)
{
.....
/**
* @Cache(
* RedisCache::class,
* attribute = {
* "ttl" = 900 //this attribute will be passed to all method of RedisCache
* }
* )
*/
public function foo(...)
{
.....
/**
* @Cache(
* RedisCache::class,
* ignore_params = {
* "param"
* }
* )
*/
public function foo(bool $param) // the cache for foo (three) is the same as for foo (false)
{
.....
/**
* @Cache(
* RedisCache::class,
* condition = {
* "nocache" = false // execute only if $nocache = false
* }
* )
*/
public function foo(bool $nocache = false)
/**
* @Cache(
* RedisCache::class,
* attribute = {
* "target" = "getData"
* }
* action = "clear" //cache chear method will be called when setData is called
* )
*/
public function setData(...)
/**
* @Cache(
* RedisCache::class,
* action = "actualize" //cache chear method will be called when setData is called
* )
*/
public function setData(...)
/**
* @Cache(
* RedisCache::class,
* actualize_condition = { //cache willbe actualize when foo is called eitch $actualize = true parameters
* "actualize" = true
* },
* clear_condition = { //cache chear method will be called when foo is called witch $clear = true parameters
* "clear" = true
* },
* ignore_params = {
* "clear", "actualize"
* }
* )
*/
public function foo(bool $clear, bool $actualize)
{
......
use Skrip42\Bundle\CacheLayerBundle\CacheManager;
use App\Services\SomeClass;
......
$cacheAccessor = CacheManager::getBy(SomeClass::class); //return CacheAccessor instance
class CacheAccessor
{
has(string $methodName, array $params = [], array $attr = []) : bool;
find(string $methodName, array $params = [], array $attr = []) : array; //return array of CacheInterface witch the value is founded;
get(string $methodName, array $params = [], array $attr = []);
set(string $methodName, $data, $params = [], array $attr = []);
clear(string $methodName, $params = [], array $attr = []);
getLayer(string $cacheServiceName) : CacheAccessor; //return cache accessor for specific cache class (get RedisCache only for example)
getCacheMap() : array; //return cache map schem for current object
}