banker/README.md

78 lines
1.8 KiB
Markdown
Raw Normal View History

2016-08-31 12:18:46 -04:00
# Banker
2016-09-06 20:57:24 -04:00
A Caching library implementing the PSR-6 interface for several common cache
backends
2017-03-01 13:07:31 -05:00
[![build status](https://git.timshomepage.net/timw4mail/banker/badges/master/build.svg)](https://git.timshomepage.net/timw4mail/banker/commits/master)
[![coverage report](https://git.timshomepage.net/timw4mail/banker/badges/master/coverage.svg)](https://git.timshomepage.net/timw4mail/banker/commits/master)
2016-09-06 20:57:24 -04:00
## Cache Backends
2017-01-17 12:36:34 -05:00
* Apcu
2016-09-06 20:57:24 -04:00
* Memcached
* Redis
* Null - no persistence
### Basic Usage
```php
2016-09-07 11:01:07 -04:00
<?php
2016-09-06 20:57:24 -04:00
// Create the pool
2016-09-07 11:01:07 -04:00
// $config is the configuration array
// $logger is an optional psr/log compatible logger
2016-09-06 20:57:24 -04:00
$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
2016-09-07 11:01:07 -04:00
<?php
$config = [
'driver' => 'null', // null, apcu, redis, memcached
2016-09-06 20:57:24 -04:00
'connection' => [
2017-02-28 16:44:02 -05:00
// Optional (For some drivers):
2016-09-06 20:57:24 -04:00
// 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
]
2016-09-07 11:01:07 -04:00
];
2016-09-06 20:57:24 -04:00
```
Below are the connection arrays for each backend:
Memcached:
2016-09-06 20:57:24 -04:00
```php
2016-09-07 11:01:07 -04:00
<?php
$config['connection'] = [
2016-09-06 20:57:24 -04:00
'host' => 'localhost', // hostname or socket
'port' => 11211, // Port needs to be 0 if socket
'persistent' => false, // Use persistent connection
2016-09-07 11:01:07 -04:00
];
2016-09-06 20:57:24 -04:00
```
Redis:
See [Predis](https://github.com/nrk/predis#connecting-to-redis) documentation. An empty array will connect to localhost on port 6379.
2017-01-17 12:36:34 -05:00
Null, Apcu:
2016-09-06 20:57:24 -04:00
No connection parameters