PSR-6 compliant caching library

Name Last Update
build Loading commit data...
src Loading commit data...
tests Loading commit data...
.editorconfig Loading commit data...
.gitignore Loading commit data...
.gitlab-ci.yml Loading commit data... Loading commit data...
RoboFile.php Loading commit data...
composer.json Loading commit data...
phpdoc.dist.xml Loading commit data...
phpunit.xml Loading commit data...


A Caching library implementing the PSR-6 interface for several common cache backends

build status coverage report

Cache Backends

  • Apcu
  • Memcache
  • Memcached
  • Redis
  • Null - no persistence

Basic Usage

// Create the pool
// $config is the configuration array
// $logger is an optional psr/log compatible logger
$pool = new Aviat\Banker\Pool($config, $logger);

// Grab an item from the cache
$item = $pool->getItem('foo');

// Was there a cache hit?
if ( ! $item->isHit())
    // ... Generation of value to cache
    $value = $item->get();

Configuration / Connection array

The config array passed to the Pool class constructor determines which server to connect to. Regardless of the backend, the basic structure is like so:

$config = [
    'driver' => 'null', // null, apcu, redis, memcache, memcached
    'connection' => [
        // Optional (For some drivers):
        // driver setup, see below for the structure for each
        // driver
    'options' => [
        // Optional:
        // Set additional driver-specific options, like persistence for
        // Memcached, or a prefix for Redis keys

Below are the connection arrays for each backend:

Memcache / Memcached:

$config['connection'] = [
    'host' => 'localhost', // hostname or socket
    'port' => 11211,       // Port needs to be 0 if socket
    'persistent' => false, // Use persistent connection

Redis: See Predis documentation. An empty array will connect to localhost on port 6379.

Null, Apcu: No connection parameters