for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Sugarcrm\UpgradeSpec\Cache\Adapter;
use Psr\SimpleCache\CacheInterface;
use Sugarcrm\UpgradeSpec\Cache\Exception\InvalidArgumentException;
/**
* PSR-16 compatible memory based cache adapter.
*/
class Memory implements CacheInterface
{
use AdapterTrait;
* @var array
private $cache = [];
* Memory constructor.
*
* @param $data
* @param $ttl
public function __construct($data = [], $ttl = 3600)
$this->validateIterableKey($data);
foreach ($data as $key => $value) {
$this->cache[$key] = [time() + $ttl, $value];
}
$this->ttl = $ttl;
* @param string $key
* @param null $default
* @return mixed
public function get($key, $default = null)
$this->validateKey($key);
if (!isset($this->cache[$key])) {
return $default;
list($expire, $value) = $this->cache[$key];
if (!is_null($expire) && $expire < time()) {
$this->delete($key);
return $value;
* @param mixed $value
* @param null $ttl
* @return bool
* @throws InvalidArgumentException
public function set($key, $value, $ttl = null)
$this->cache[$key] = [$this->getExpire($ttl), $value];
return true;
public function delete($key)
if (!$this->has($key)) {
return false;
unset($this->cache[$key]);
public function clear()
$this->cache = [];
public function has($key)
return isset($this->cache[$key]);