A caching library implementing PSR-6 and PSR-16 interfaces
Go to file
Timothy J Warren edea686f4c
Some checks failed
Gitea - aviat/banker/master There was a failure building this commit
Jenkins CI setup, try eight
2018-10-12 10:53:48 -04:00
build Update header comments 2017-03-01 12:33:12 -05:00
src Minor code style improvements 2017-03-01 13:04:00 -05:00
tests Minor code style improvements 2017-03-01 13:04:00 -05:00
.editorconfig First commit 2016-08-31 12:18:46 -04:00
.gitignore First commit 2016-08-31 12:18:46 -04:00
.gitlab-ci.yml Make sure we can connect to memcached 2017-03-01 12:04:01 -05:00
composer.json Minor code style improvements 2017-03-01 13:04:00 -05:00
Jenkinsfile Jenkins CI setup, try eight 2018-10-12 10:53:48 -04:00
phpdoc.dist.xml First commit 2016-08-31 12:18:46 -04:00
phpunit.xml First commit 2016-08-31 12:18:46 -04:00
README.md Update README 2017-03-01 13:07:31 -05:00
RoboFile.php PHP 7 or bust! 2016-10-19 09:57:06 -04:00

Banker

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

<?php
// 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
	$item->set($value);
	$item->save();
}
else
{
	$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:

<?php
$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:

<?php
$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