2017 © Pedro Peláez
 

library universal-cache

A Generic PHP Cache Interface with Cascade Caching

image

corneltek/universal-cache

A Generic PHP Cache Interface with Cascade Caching

  • Saturday, June 11, 2016
  • by c9s
  • Repository
  • 2 Watchers
  • 20 Stars
  • 6,818 Installations
  • PHP
  • 6 Dependents
  • 0 Suggesters
  • 1 Forks
  • 3 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

UniversalCache

Build Status Latest Stable Version Latest Unstable Version Total Downloads Monthly Downloads License, (*1)

A Generic PHP Cache Interface with Cascade Caching., (*2)

DESCRIPTION

This package was inspired by a Perl module - Cache::Cascade., (*3)

In a multiprocess, and especially a multiserver application caching is a very effective means of improving results., (*4)

The tradeoff of increasing the scale of the caching is in added complexity. For example, caching in a FastMmap based storage is much slower than using a memory based cache, because pages must be locked to ensure that no corruption will happen. Likewise Memcached is even more overhead than FastMmap because it is network bound, and uses blocking IO (on the client side)., (*5)

This module attempts to make a transparent cascade of caches using several backends., (*6)

The idea is to search from the cheapest backend to the most expensive, and depending on the options also cache results in the cheaper backends., (*7)

The benefits of using a cascade are that if the chance of a hit is much higher in a slow cache, but checking a cheap cache is negligible in comparison, we may already have the result we want in the cheap cache. Configure your expiration policy so that there is approximately an order of magnitude better probability of cache hits (bigger cache) for each level of the cascade., (*8)

INSTALL

composer require corneltek/universal-cache

UniversalCache

UniversalCache class provides a consistent interface to operate on different cache backend, you may put the fastest cache backend on the first position, so that you can fetch the cache very quickly when there is a fresh cache in the fastest storage., (*9)

use UniversalCache\ApcuCache;
use UniversalCache\FileSystemCache;
use UniversalCache\UniversalCache;

$cache = new UniversalCache([
    new ArrayCache, // Fetch cache without serialization if there is a request-wide cache exists.
    new ApcuCache('app_', 60), // Faster then file system cache.
    new FileSystemCache(__DIR__ . '/cache'),
]);
$cache->set('key', 'value');
$value = $cache->get('key');

ApcuCache

$cache = new UniversalCache\ApcuCache('app_', 3600); // 3600 = expiry time
$cache->set($name,$val);
$val = $cache->get($name);
$cache->remove($name);

ArrayCache

ArrayCache implements a pure php based cache, the cache is not persistent between different request. However, it made the request-wide cache simple., (*10)

$cache = new UniversalCache\ArrayCache;
$cache->set($name,$val);
$val = $cache->get($name);
$cache->remove($name);

MemcacheCache

$cache = new UniversalCache\MemcacheCache([
    'servers' => [['localhost', 123123], ['server2',123123] ]
]);
$cache->set($name,$val);
$val = $cache->get($name);
$cache->remove($name);

RedisCache

$cache = new UniversalCache\RedisCache($redisConnection);
$cache->set($name,$val);
$val = $cache->get($name);
$cache->remove($name);

FileSystemCache

$serializer = new SerializerKit\JsonSerializer();
$cache = new UniversalCache\FileSystemCache(__DIR__ . '/cache', [
    'expiry' => 30,
    'serializer' => $serializer,
]);

Hacking

Install dependencies, (*11)

composer install --prefer-source

Install redis extension, (*12)

phpbrew ext install github:phpredis/phpredis php7

Install memcached extension, (*13)

phpbrew ext install github:php-memcached-dev/php-memcached php7 -- --disable-memcached-sasl

Install APCu extension, (*14)

phpbrew ext install github:krakjoe/apcu

Be sure to enable apcu and cli mode, (*15)

apc.enabled=1
apc.enable_cli=1

Run tests, (*16)

phpunit

LICENSE

This package is released under MIT license., (*17)

The Versions

11/06 2016

dev-master

9999999-dev http://github.com/corneltek/UniversalCache

A Generic PHP Cache Interface with Cascade Caching

  Sources   Download

MIT

The Requires

 

The Development Requires

11/06 2016

3.3.0

3.3.0.0 http://github.com/corneltek/UniversalCache

A Generic PHP Cache Interface with Cascade Caching

  Sources   Download

MIT

The Requires

 

The Development Requires

11/06 2016

3.2.1

3.2.1.0 http://github.com/corneltek/UniversalCache

A Generic PHP Cache Interface with Cascade Caching

  Sources   Download

MIT

The Requires

 

The Development Requires

11/06 2016

3.2.0

3.2.0.0 http://github.com/c9s/UniversalCache

A Generic PHP Cache Interface with Cascade Caching

  Sources   Download

MIT

The Requires

 

The Development Requires

11/06 2016

3.1.0

3.1.0.0 http://github.com/c9s/UniversalCache

General cache interface

  Sources   Download

MIT

The Requires

 

The Development Requires

10/06 2016

3.0.0

3.0.0.0 http://github.com/c9s/UniversalCache

General cache interface

  Sources   Download

MIT

The Requires

 

The Development Requires

26/03 2013

1.0.6

1.0.6.0 http://github.com/c9s/UniversalCache

General cache interface

  Sources   Download

MIT

The Requires

 

The Development Requires