PHP code example of mima / cache-proxy

1. Go to this page and download the library: Download mima/cache-proxy 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/ */

    

mima / cache-proxy example snippets


use CacheProxy\Proxy;
use CacheProxy\Adapter\DoctrinCacheAdapter;

$adapter = new DoctrinCacheAdapter($doctrinCacheInstance);
$cacheProxy = new Proxy($adapter);

use MyNamespace\AnyClass;
use CacheProxy\Target\ProxyTarger;

$object = new AnyClass();
$target = new ProxyTarget([$object, 'anyMethod'], ['arg1', 'arg2']);

$data = $cacheProxy->proxyTarget($target);

namespace MyNamespace;

use CacheProxy\Proxy

class AnyDecorator
{
    /**
     * @var AnyClass
     */
    protected $class;
    /**
     * @var Proxy
     */
    protected $proxy;

    public function __construct(AnyClass $class, Proxy $cacheProxy)
    {
        $this->class = $class;
        $this->cacheProxy = $proxy;
    }

    public function anyMethod($arg1, $arg2)
    {
        $target = new ProxyTarget([$this->class, 'anyMethod'], func_get_args());

        return $this->cacheProxy->proxyTarget($target);
    }
}

$cityId = 1;
$cacheProxy->proxyTarget($target, $cityId);

$ttl = 3600;
$cacheProxy->proxyTarget($target, null, $ttl);

// this code update cache ad return data
$key = md5('any-key');
$cacheProxy->proxyTarget($target, null, $ttl);

// this code flush all data from cache by target and key
$cacheProxy->flushTarget($target, $key);