|
1 year ago | |
---|---|---|
build | 1 year ago | |
src | 1 year ago | |
tests | 1 year ago | |
.editorconfig | 3 years ago | |
.gitignore | 3 years ago | |
.gitlab-ci.yml | 2 years ago | |
CHANGELOG.md | 1 year ago | |
Jenkinsfile | 1 year ago | |
README.md | 1 year ago | |
RoboFile.php | 3 years ago | |
composer.json | 1 year ago | |
phpdoc.dist.xml | 3 years ago | |
phpunit.xml | 3 years ago |
A Caching library implementing the PSR-6 interface for several common cache backends
<?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();
}
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