2017 © Pedro Peláez
 

project tumbleweed-cache

PHP caching implementation of PSR-6

image

jmatosp/tumbleweed-cache

PHP caching implementation of PSR-6

  • Thursday, January 14, 2016
  • by jmatosp
  • Repository
  • 3 Watchers
  • 15 Stars
  • 855 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 9 Versions
  • 10 % Grown

The README.md

TumbleweedCache

Build Status Coverage Status Latest Stable Version, (*1)

PHP Caching - PSR-6 implementation, (*2)

This library provides Calling Libraries abstract cache services., (*3)

Implementations for well known cache infrastructure, clever cache using multi-level/failover cache and clustered like cache., (*4)

Drivers available: APCu, Redis, Files, Memcached, Memory, 2 Level Cache, (*5)

All drivers where tested using PHPUnit and a great 3rd party testing suite for PSR-6, (*6)

Install

composer require jmatosp/tumbleweed-cache

Usage

Simple to use, Tumbleweed Cache will try to use one of the available drivers APCu, Redis or Files, (*7)

$cache = CacheFactory::make();
$item = $cache->getItem('my_key')
            ->set('value')
            ->expiresAfter(60);
$cache->save($item);
echo $cache->getItem('my_key')->get();
// will output "value"

or not using CacheFactory and instantiating APCu directly, (*8)

$cache = new APCuCache();
$cache->getItem('hello')->set('value');
echo $cache->getItem('hello')->get();   // output: "value"

You can specify the cache implementation to use:, (*9)

APCu, (*10)

This driver supports both apc and apcu, works with HHVM (legacy), apcu only PHP7 and apc/apcu on PHP5.6, (*11)

$cache = CacheFactory::make(CacheFactory::APCU);
$item = $cache->getItem('my_key')->set('value');
$cache->save($item);
echo $cache->getItem('my_key')->get();
// will output "value"

Redis, (*12)

You can use the factory to create a Redis cache instance, factory will try to connect to default port on localhost, or you can provide a connection as in this example., (*13)

$redis = new Redis();
$redis->connect('127.0.0.1');
$cache = CacheFactory::make(CacheFactory::REDIS, $redis);
$item = $cache->getItem('my_key')->set('value');
$cache->save($item);
echo $cache->getItem('my_key)->get();
// will output "value"

Files, (*14)

File base cache interface, fast and uses /tmp directory. Cache factory will check if TMP dir is writable and throw and exception if not., (*15)

$cache = CacheFactory::make(CacheFactory::FILE);
$item = $cache->getItem('my_key')->set('value');
$cache->save($item);
echo $cache->getItem('my_key)->get();
// will output "value"

Memcache, (*16)

$memcached = new Memcached('my_app_ip');
$memcached->addServer('localhost', 11211);
$cache = CacheFactory::make(CacheFactory::MEMCACHED, $memcached);
$item = $cache->getItem('my_key')->set('value');
$cache->save($item);
echo $cache->getItem('my_key)->get();
// will output "value"

Two level, (*17)

Two level cache aims to use 2 cache repositories, as failover with two remote caches or a combination of one local to with faster access like APCu and one remote typically Redis or Memcached. Also good to work as a failover cache in case of the first one fails. Sample using APCu as first level (faster) and Redis second level (fast), (*18)

$localCache = CacheFactory::make(CacheFactory::APCU);
$remoteCache = CacheFactory::make(CacheFactory::REDIS);
$megaCache = CacheFactory::make(CacheFactory::TWO_LEVEL, $localCache, $remoteCache);
$item = $cache->getItem('my_key')->set('value');
$cache->save($item);
echo $cache->getItem('my_key')->get();
// will output "value"

Cache Factory

Cache factory enables creation to different type of cache infrastructure with an easy interface., (*19)

It has a builtin auto-discovery that will try to find the fastest one available, to use the auto-discovery simply call the factory without parameters:, (*20)

$cacheService = CacheFactory::make();

Auto-discovery will try to use cache infrastructure by this order: APCu, APC, File, Redis, (*21)

PSR-6 Cache Interface

All cache item pool implementations use PSR-6 interfaces, for details please visit PHP-FIG PSR-6: Caching Interface, (*22)

Running tests

To run all test including integration you need:, (*23)

  • Redis - installed locally on standard port 127.0.0.1:6379
  • APCu - edit your php.ini and add "apc.enable_cli=1" after the extension loading to enable tests on APCu
  • Memcached

Optionally you can run on the provided Vagrant box:, (*24)

vagrant up
vagrant ssh
cd /vagrant
composer install
vendor/bin/phpunit

The Versions

14/01 2016

dev-cachePoolObserver

dev-cachePoolObserver

PHP caching implementation of PSR-6

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jose Pinto

cache redis memcache apc psr6

13/01 2016

dev-master

9999999-dev

PHP caching implementation of PSR-6

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jose Pinto

cache redis memcache apc psr6

13/01 2016

1.2.4

1.2.4.0

PHP caching implementation of PSR-6

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jose Pinto

cache redis memcache apc psr6

13/01 2016

1.2.3

1.2.3.0

PHP caching implementation of PSR-6

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jose Pinto

cache redis memcache apc psr6

12/01 2016

1.2.2

1.2.2.0

PHP caching implementation of PSR-6

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jose Pinto

cache redis memcache apc psr6

12/01 2016

1.2.1

1.2.1.0

PHP caching implementation of PSR-6

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jose Pinto

cache redis memcache apc psr6

11/01 2016

1.2.0

1.2.0.0

PHP caching implementation of PSR-6

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jose Pinto

cache redis memcache apc psr6

07/01 2016

1.1.0

1.1.0.0

PHP caching implementation of PSR-6

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jose Pinto

cache redis memcache apc psr6

06/01 2016

1.0.0

1.0.0.0

PHP caching implementation of PSR-6

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jose Pinto

cache redis memcache apc psr6