2017 © Pedro Peláez
 

library cache

Webiny Cache Component

image

webiny/cache

Webiny Cache Component

  • Friday, September 29, 2017
  • by SvenAlHamad
  • Repository
  • 2 Watchers
  • 1 Stars
  • 144 Installations
  • PHP
  • 4 Dependents
  • 1 Suggesters
  • 0 Forks
  • 0 Open issues
  • 23 Versions
  • 0 % Grown

The README.md

Cache Component

Cache component give you ability to store different information into memory for a limited time., (*1)

Install the component

The best way to install the component is using Composer., (*2)

composer require webiny/cache

For additional versions of the package, visit the Packagist page., (*3)

Supported drivers

The cache component supports following cache drivers: * APC (http://php.net/manual/en/book.apc.php) - only available in PHP 5.4, from PHP 5.5 APC is not supported * Couchbase (http://www.couchbase.com/develop/php/current) * Memcache (http://php.net/manual/en/book.memcache.php) * Redis (http://redis.io/clients), (*4)

If you are not sure which driver to use, we suggest Memcache., (*5)

Based on the selected driver, you'll have to pass different options to the constructor., (*6)

Requirements

The default bridged library is Memory by Jamm (https://github.com/jamm/Memory). It is required that you add this library to the ClassLoader :, (*7)

    \Webiny\Components\ClassLoader::getInstance()->registerMap(['Jamm\Memory' => 'path to memory lib']);

For example:, (*8)

    // APC
    $cache = \Webiny\Component\Cache\Cache::APC('cache-id');

    // Couchbase
    $cache = \Webiny\Component\Cache\Cache::Couchbase('CacheService', 'username', 'password', 'bucket', '127.0.0.1:8091');

    // Memcache
    $cache = \Webiny\Component\Cache\Cache::Memcache('CacheService', 'localhost', 11211);

    // Redis
    $cache = \Webiny\Component\Cache\Cache::Redis('CacheService', 'localhost', 6379);

Common operations

Once you have created your Cache instance, you can start using your cache. The cache methods are the same, no matter which driver you use:, (*9)

    // write to cache
    $cache->save('myKey', 'some value', 600, ['tag1', 'tag2']);

    // read from cache
    $cache->read('myKey');

    // delete from cache
    $cache->delete('myKey');

    // delete by tag
    $cache->deleteByTag(['tag1']);

Cache config

The preferred way of defining cache drivers is creating them inside your the config file of your application., (*10)

    Cache:
      TestCache:
        Factory: "\Webiny\Component\Cache\Cache"
        Method: "Apc"
      SomeOtherCache:
          Factory: "\Webiny\Component\Cache\Cache"
          Method: "Memcache"
          Arguments: ['127.0.0.1', '11211']

See the ExampleConfig.yaml for additional details., (*11)

Under Cache you define the cache drivers by giving each of them a cache id and underneath you nest its config. The driver configuration depends on which driver you are using., (*12)

If you wish to turn off the cache, use the BlackHole driver., (*13)

The Method parameter must be a valid callback function that will return an instance of CacheStorage., (*14)

The benefit of defining cache drivers in this way is that the drivers are initialized the second Webiny Framework is loaded. This enables you to access the cache by 'CacheTrait'., (*15)

    class MyClass
    {
        use \Webiny\Component\Cache\CacheTrait;

        public function myMethod(){
            $this->cache('Frontend')->read('cache_key');
        }
    }

Custom Cache driver

To implement you own custom cache driver you must first create a class that will implement \Webiny\Component\Cache\Bridge\CacheInterface. Once you have that class, create another class with a static function that will return an instance of CacheDriver., (*16)

    class CustomCacheDriver implements \Webiny\Component\Cache\Bridge\CacheInterface
    {
        // implement the interface methods

        // static method that will return the CacheDriver
        function getDriver($cacheId, $param1, $param2, array $options){
            $driver = new static($cacheId, $param1, $param2);

            return \Webiny\Component\Cache\CacheDriver($driver, $options);
        }
    }

Now just set your class and the static method as the Method inside your config and you can access the cache over the CacheTrait., (*17)

Resources

To run unit tests, you need to use the following command:, (*18)

$ cd path/to/Webiny/Component/Cache/
$ composer.phar install
$ phpunit

Make sure that you also set your cache driver details in Tests/ExampleConfig.yaml., (*19)

The Versions

29/09 2017

dev-master

9999999-dev http://www.webiny.com/

Webiny Cache Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

cache redis memcache apc couchbase

29/09 2017

1.6.x-dev

1.6.9999999.9999999-dev http://www.webiny.com/

Webiny Cache Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

cache redis memcache apc couchbase

29/09 2017

v1.6.0

1.6.0.0 http://www.webiny.com/

Webiny Cache Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

cache redis memcache apc couchbase

29/09 2017

v1.6.1

1.6.1.0 http://www.webiny.com/

Webiny Cache Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

cache redis memcache apc couchbase

08/09 2017

1.5.x-dev

1.5.9999999.9999999-dev http://www.webiny.com/

Webiny Cache Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

cache redis memcache apc couchbase

08/09 2017

v1.5.0

1.5.0.0 http://www.webiny.com/

Webiny Cache Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

cache redis memcache apc couchbase

21/08 2016

1.4.x-dev

1.4.9999999.9999999-dev http://www.webiny.com/

Webiny Cache Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

cache redis memcache apc couchbase

21/08 2016

v1.4.3

1.4.3.0 http://www.webiny.com/

Webiny Cache Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

cache redis memcache apc couchbase

04/02 2016

v1.4.0

1.4.0.0 http://www.webiny.com/

Webiny Cache Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

cache redis memcache apc couchbase

04/02 2016

v1.4.1

1.4.1.0 http://www.webiny.com/

Webiny Cache Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

cache redis memcache apc couchbase

04/02 2016

v1.4.2

1.4.2.0 http://www.webiny.com/

Webiny Cache Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

cache redis memcache apc couchbase

16/03 2015

1.3.x-dev

1.3.9999999.9999999-dev http://www.webiny.com/

Webiny Cache Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

cache redis memcache apc couchbase

16/03 2015

v1.3.0

1.3.0.0 http://www.webiny.com/

Webiny Cache Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

cache redis memcache apc couchbase

05/02 2015

v1.2.2

1.2.2.0 http://www.webiny.com/

Webiny Cache Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

cache redis memcache apc couchbase

05/02 2015

v1.2.3

1.2.3.0 http://www.webiny.com/

Webiny Cache Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

cache redis memcache apc couchbase

04/02 2015

1.2.x-dev

1.2.9999999.9999999-dev http://www.webiny.com/

Webiny Cache Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

cache redis memcache apc couchbase

04/02 2015

v1.2.0

1.2.0.0 http://www.webiny.com/

Webiny Cache Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

cache redis memcache apc couchbase

04/02 2015

v1.2.1

1.2.1.0 http://www.webiny.com/

Webiny Cache Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

cache redis memcache apc couchbase

28/11 2014

v1.1.1

1.1.1.0 http://www.webiny.com/

Webiny Cache Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

cache redis memcache apc couchbase

23/11 2014

1.1.x-dev

1.1.9999999.9999999-dev http://www.webiny.com/

Webiny Cache Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

cache redis memcache apc couchbase

23/11 2014

v1.1.0

1.1.0.0 http://www.webiny.com/

Webiny Cache Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

cache redis memcache apc couchbase

19/09 2014

1.0.x-dev

1.0.9999999.9999999-dev http://www.webiny.com/

Webiny Cache Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

cache redis memcache apc couchbase

19/09 2014

v1.0.0

1.0.0.0 http://www.webiny.com/

Webiny Cache Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

cache redis memcache apc couchbase