You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Timothy Warren d1d1085d10 Update header comments 10 months ago
build Remove Memcache, improve test coverage, fix bugs 10 months ago
src Update header comments 10 months ago
tests Update header comments 10 months ago
.editorconfig First commit 3 years ago
.gitignore First commit 3 years ago
.gitlab-ci.yml Make sure we can connect to memcached 2 years ago
CHANGELOG.md Remove Memcache, improve test coverage, fix bugs 10 months ago
Jenkinsfile Jenkins CI setup, try eight 11 months ago
README.md Remove Memcache, improve test coverage, fix bugs 10 months ago
RoboFile.php PHP 7 or bust! 2 years ago
composer.json Remove Memcache, improve test coverage, fix bugs 10 months ago
phpdoc.dist.xml First commit 3 years ago
phpunit.xml First commit 3 years ago

README.md

Banker

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

build status coverage report

Cache Backends

  • Apcu
  • 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, 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:

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