Add NullDriver for cache layer, for the sake of testing, or config without a cache
This commit is contained in:
parent
5d0b879623
commit
7d6c6fe2a0
@ -14,8 +14,8 @@ show_anime_collection = true
|
||||
# do you wish to show the manga collection?
|
||||
show_manga_collection = false
|
||||
|
||||
# cache driver for api calls (SQLDriver, RedisDriver)
|
||||
cache_driver = SQLDriver
|
||||
# cache driver for api calls (NullDriver, SQLDriver, RedisDriver)
|
||||
cache_driver = NullDriver
|
||||
|
||||
# path to public directory on the server
|
||||
asset_dir = "/../../public"
|
@ -34,7 +34,7 @@ class CacheManager implements CacheInterface {
|
||||
|
||||
if (empty($driverConf))
|
||||
{
|
||||
$driverConf = 'SQLDriver';
|
||||
$driverConf = 'NullDriver';
|
||||
}
|
||||
|
||||
$driverClass = __NAMESPACE__ . "\\Driver\\{$driverConf}";
|
||||
|
83
src/Aviat/Ion/Cache/Driver/NullDriver.php
Normal file
83
src/Aviat/Ion/Cache/Driver/NullDriver.php
Normal file
@ -0,0 +1,83 @@
|
||||
<?php
|
||||
/**
|
||||
* Ion
|
||||
*
|
||||
* Building blocks for web development
|
||||
*
|
||||
* @package Ion
|
||||
* @author Timothy J. Warren
|
||||
* @copyright Copyright (c) 2015 - 2016
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
namespace Aviat\Ion\Cache\Driver;
|
||||
|
||||
use Aviat\Ion\Di\ContainerInterface;
|
||||
|
||||
/**
|
||||
* The Driver for no real cache
|
||||
*/
|
||||
class NullDriver implements \Aviat\Ion\Cache\CacheDriverInterface {
|
||||
|
||||
/**
|
||||
* 'Cache' for Null data store
|
||||
*/
|
||||
protected $data;
|
||||
|
||||
/**
|
||||
* Create the Redis cache driver
|
||||
*/
|
||||
public function __construct(ContainerInterface $container)
|
||||
{
|
||||
$this->data = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Retreive a value from the cache backend
|
||||
*
|
||||
* @param string $key
|
||||
* @return mixed
|
||||
*/
|
||||
public function get($key)
|
||||
{
|
||||
return (array_key_exists($key, $this->data))
|
||||
? $this->data[$key]
|
||||
: NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a cached value
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return CacheDriverInterface
|
||||
*/
|
||||
public function set($key, $value)
|
||||
{
|
||||
$this->data[$key] = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invalidate a cached value
|
||||
*
|
||||
* @param string $key
|
||||
* @return CacheDriverInterface
|
||||
*/
|
||||
public function invalidate($key)
|
||||
{
|
||||
unset($this->data[$key]);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the contents of the cache
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function invalidateAll()
|
||||
{
|
||||
$this->data = [];
|
||||
}
|
||||
}
|
||||
// End of NullDriver.php
|
17
tests/Ion/Cache/Driver/NullDriverTest.php
Normal file
17
tests/Ion/Cache/Driver/NullDriverTest.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
require_once('CacheDriverBase.php');
|
||||
|
||||
use Aviat\Ion\Cache\Driver\NullDriver;
|
||||
|
||||
class CacheNullDriverTest extends AnimeClient_TestCase {
|
||||
use CacheDriverBase;
|
||||
|
||||
protected $driver;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->driver = new NullDriver($this->container);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user