2017 © Pedro Peláez
 

library php-cache

LinguaLeo Caching Library

image

lingualeo/php-cache

LinguaLeo Caching Library

  • Saturday, April 22, 2017
  • by LinguaLeo
  • Repository
  • 22 Watchers
  • 2 Stars
  • 10,188 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 20 Versions
  • 2 % Grown

The README.md

php-cache

PHP-Cache is a library designed to simplify your work with the different cache storage engines. Currently library is under heavy development so API can change in the future., (*1)

Example using Redis:, (*2)

$redis = new \Redis();
$redis->connect('127.0.0.1');
$cache = new RedisCache($redis);

$cache->set('test', 'data'); //write 'data' by key 'test'
$cache->get('test'); //returns 'data'

Also atomic CAS-like operations supported (create and update). For example:, (*3)

$modifier = function (&$data) {
    $data = 'value';
};
$result = $this->cache->create('test', $modifier);

Data represents the reference to information that storage already contains. You can modify or completly replace it inside the callable., (*4)

If other client will change Data before you call create you will get an AtomicViolationException. In your client code you can catch this exception and retry operation., (*5)

The main difference betweeen create and update methods is that update will do nothing in case storage doesn't contains the specified key., (*6)

Decorators

Currently library provides only one additional HotCacheDecorator which is very useful in a highloaded environment: it simply stores (and modifies) all cached data in a in-memory array. So if you call get once then all subsequent calls will be served only by hot cache without any requests to storage server., (*7)

To enable hot cache just wrap your creation of any CacheProvider object with the decorator:, (*8)

$redis = new \Redis();
$redis->connect('127.0.0.1');
$cache = new HotCacheDecorator(new RedisCache($redis));

Cache key generation

Library provides simple mechanism to generate cache keys with generateCacheKey method of CacheProvider:, (*9)

$key = CacheProvider::generateCacheKey('arg1', 'arg2'); //cache:arg1:arg2

You can pass any number of arguments (> 0) to this method in order to get a fresh shiny cache key. Also as the first parameter you can pass some class name and if this class will contain constant field VERSION then it's value will be mixed up with other arguments of generateCacheKey:, (*10)

class Test {
    const VERSION = 2;
}
...
$key = CacheProvider::generateCacheKey('Test', 'arg1', 'arg2'); //cache:Test:arg1:arg2:2

This behavior is very useful when you work with ORM models and want to cache different versions of objects without need to drop all cache data after making some changes in a small single model., (*11)

Testing

Setup Vagrant and Virtualbox., (*12)

vagrant up
phpunit

The Versions

22/04 2017

dev-master

9999999-dev

LinguaLeo Caching Library

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Avatar LinguaLeo

22/04 2017

0.9.0

0.9.0.0

LinguaLeo Caching Library

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Avatar LinguaLeo

05/05 2016

dev-feature/dev-4498-timer-for-memcache-redis

dev-feature/dev-4498-timer-for-memcache-redis

LinguaLeo Caching Library

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Avatar LinguaLeo

27/04 2016

0.8.1

0.8.1.0

LinguaLeo Caching Library

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Avatar LinguaLeo

11/12 2015

0.8.0

0.8.0.0

LinguaLeo Caching Library

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Avatar LinguaLeo

07/10 2015

0.7.7

0.7.7.0

LinguaLeo Caching Library

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Avatar LinguaLeo

12/12 2014

0.7.6

0.7.6.0

LinguaLeo Caching Library

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

  • ext-redis *

by Avatar LinguaLeo

18/11 2014

0.7.5

0.7.5.0

LinguaLeo Caching Library

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

  • ext-redis *

by Avatar LinguaLeo

20/10 2014

0.7.4

0.7.4.0

LinguaLeo Caching Library

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

  • ext-redis *

by Avatar LinguaLeo

26/09 2014

0.7.3

0.7.3.0

LinguaLeo Caching Library

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

  • ext-redis *

by Avatar LinguaLeo

25/09 2014

0.7.2

0.7.2.0

LinguaLeo Caching Library

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

  • ext-redis *

by Avatar LinguaLeo

18/09 2014

0.7.1

0.7.1.0

LinguaLeo Caching Library

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

  • ext-redis *

by Avatar LinguaLeo

18/09 2014

dev-feature/sd-523-create-memcached

dev-feature/sd-523-create-memcached

LinguaLeo Caching Library

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

  • ext-redis *

by Avatar LinguaLeo

17/09 2014

0.7.0

0.7.0.0

LinguaLeo Caching Library

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

  • ext-redis *

by Avatar LinguaLeo

19/05 2014

0.6.0

0.6.0.0

LinguaLeo Caching Library

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

  • ext-redis *

by Avatar LinguaLeo

10/02 2014

0.5

0.5.0.0

LinguaLeo Caching Library

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Avatar LinguaLeo

09/02 2014

0.4

0.4.0.0

LinguaLeo Caching Library

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Avatar LinguaLeo

27/11 2013

0.3

0.3.0.0

LinguaLeo Caching Library

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Avatar LinguaLeo

26/11 2013

0.2

0.2.0.0

LinguaLeo Caching Library

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Avatar LinguaLeo

26/11 2013

0.1

0.1.0.0

LinguaLeo Caching Library

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Avatar LinguaLeo