for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* Class MemoryCache
*
* @filesource MemoryCache.php
* @created 27.05.2017
* @package chillerlan\SimpleCache
* @author Smiley <[email protected]>
* @copyright 2017 Smiley
* @license MIT
*/
namespace chillerlan\SimpleCache;
class MemoryCache extends CacheDriverAbstract{
* @var array
protected $cache = [];
/** @inheritdoc */
public function get($key, $default = null){
$this->checkKey($key);
if(isset($this->cache[$key])){
if($this->cache[$key]['ttl'] === null || $this->cache[$key]['ttl'] > time()){
return $this->cache[$key]['content'];
}
unset($this->cache[$key]);
return $default;
public function set($key, $value, $ttl = null):bool{
$ttl = $this->getTTL($ttl);
$this->cache[$key] = [
'ttl' => $ttl ? time() + $ttl : null,
'content' => $value,
];
return true;
public function delete($key):bool{
public function clear():bool{
$this->cache = [];