graphstory/cache-interface

Generic cache interfaces

0.0.3 2015-11-20 17:37 UTC

This package is not auto-updated.

Last update: 2024-04-13 17:07:45 UTC


README

Simple cache adapters and interface based on Anthony Ferrara's blog post A Followup To An Open Letter To PHP-FIG.

Build Status

Installation

Using Composer

Use Composer to install the cache-interface library:

$ composer require graphstory/cache-interface

Usage

// Example using Daniel González's Cache library

use Desarrolla2\Cache\Cache;
use Desarrolla2\Cache\Adapter\File;
use GraphStory\Console\Cache\DesarrollaAdapter;

$cacheDir = '/tmp';
$adapter = new File($cacheDir);
$adapter->setOption('ttl', 3600);
$desarrolla2 = new Cache($adapter);
$cache = DesarrollaAdapter($desarrolla2);

$cache->set('key', 'myKeyValue', 3600);

// later ...

echo $cache->get('key');

(The above example was mostly cribbed from the desarrolla2/Cache documentation.)

BYOA (bring your own adapter)

You can write your own adapter by creating a class that implements the CacheAdapter interface. Use the other adapters as a reference and you should be good to go!