Maslosoft Cache API
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
<?php
/**
* This software package is licensed under New BSD license.
*
* @package maslosoft/cache
* @licence New BSD
*
* @copyright Copyright (c) Peter Maselkowski <pmaselkowski@gmail.com>
*
*/
namespace Maslosoft\Cache\Adapters;
use Maslosoft\Cache\Interfaces\CacheAdapterInterface;
/**
* Static
*
* @author Piotr Maselkowski <pmaselkowski at gmail.com>
*/
class StaticVar implements CacheAdapterInterface
{
private static $_values = [];
private static $_ttls = [];
public function get($key)
{
if ($this->has($key))
{
return self::$_values[$key];
}
return null;
}
public function has($key)
{
if(!array_key_exists($key, self::$_ttls))
{
return false;
}
$ttl = self::$_ttls[$key];
if(0 === $ttl)
{
return true;
}
return $ttl >= time();
}
public function isAvailable()
{
return true;
}
public function set($key, $data, $timeout = null)
{
self::$_values[$key] = $data;
if ($timeout !== null && $timeout > 0)
{
$ttl = time() + $timeout;
}
else
{
$ttl = 0;
}
self::$_ttls[$key] = $ttl;
}
public function clear()
{
self::$_values = [];
self::$_ttls = [];
}
public function remove($key)
{
unset(self::$_values[$key]);
unset(self::$_ttls[$key]);
}
}
API documentation generated by ApiGen