2017 © Pedro Peláez
 

library cache-proxy

Decorator for public methods of any classes for proxy request to cache

image

mima/cache-proxy

Decorator for public methods of any classes for proxy request to cache

  • Tuesday, September 27, 2016
  • by MimaTomis
  • Repository
  • 1 Watchers
  • 0 Stars
  • 7 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

PHP Cache Proxy

Build Status, (*1)

About library

Proxying calls to any functions to retrieve data from the cache., (*2)

Installation

Run command:, (*3)

composer require mima/cache-proxy

Add dependency on your composer.json:, (*4)

{
    "require": {
        "mima/cache-proxy": "~1.0"
    }
}

Using

Update cache and retrieve data

Create new instance of CacheProxy\Proxy class:, (*5)

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

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

The adapter should implement the interface CacheProxy\Adapter\CacheAdapterInterface. It is used to adapt the interface to caching in your framework., (*6)

You can use one of several prepared adapters or create your own:, (*7)

  • CacheProxy\Adapter\DoctrinCacheAdapter implementation for doctrine cache
  • CacheProxy\Adapter\YiiCacheAdapter implementation for yii2

Use instance of CacheProxy\Proxy class in your code as it is:, (*8)

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

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

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

Or you may create decorator for your class and depend him from CacheProxy\Proxy class:, (*9)

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);
    }
}

Key for caching data generated on runtime in CacheProxy\Proxy class. If you want specify any suffix for cache key, pass second argument to CacheProxy\Proxy::proxyTarget method., (*10)

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

To set the ttl for storing data in cache, pass third argument to CacheProxy\Proxy::proxyTarget method., (*11)

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

Flush data from cache

If you want remove all cache data, do as shown below:, (*12)

// 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);

The Versions

27/09 2016

dev-master

9999999-dev

Decorator for public methods of any classes for proxy request to cache

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Dmitriy Konev

27/09 2016

dev-develop

dev-develop

Decorator for public methods of any classes for proxy request to cache

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Dmitriy Konev

20/09 2016

v1.1

1.1.0.0

Decorator for public methods of any classes for proxy request to cache

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Dmitriy Konev

16/05 2016

v1.0

1.0.0.0

Decorator for public methods of any classes for proxy request to cache

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Dmitriy Konev