Non-persistent memory based cache.
Constructor.
| Type | Description |
|---|---|
| array | Configuration |
NULL
public function __construct(array $config)
{
// Nothing here
}
Store variable in the cache.
| Type | Description |
|---|---|
| string | Cache key |
| mixed | The variable to store |
| int | (optional) Time to live |
boolean
public function write($key, $value, $ttl = 0)
{
$ttl = (((int) $ttl === 0) ? 31556926 : (int) $ttl) + time();
$this->cache[$key] = array('data' => $value, 'ttl' => $ttl);
return true;
}
Fetch variable from the cache.
| Type | Description |
|---|---|
| string | Cache key |
mixed
public function read($key)
{
if(isset($this->cache[$key]))
{
if($this->cache[$key]['ttl'] > time())
{
return $this->cache[$key]['data'];
}
else
{
$this->delete($key);
return false;
}
}
else
{
return false;
}
}
Delete a variable from the cache.
| Type | Description |
|---|---|
| string | Cache key |
boolean
public function delete($key)
{
if(isset($this->cache[$key]))
{
unset($this->cache[$key]);
return true;
}
else
{
return false;
}
}
Clears the user cache.
boolean
public function clear()
{
$this->cache = array();
return true;
}
Fetches variable from cache and stores it if it doesn't exist.
| Type | Description |
|---|---|
| string | Cache key |
| closure | Closure (anonymous function) that returns value to store if it doesn't already exist |
| int | (optional) Time to live |
mixed
Magic setter.
| Type | Description |
|---|---|
| string | Cache key |
| mixed | The variable to store |
NULL
Magic getter.
| Type | Description |
|---|---|
| string | Cache key |
mixed
Magic isset.
| Type | Description |
|---|---|
| string | Cache key |
boolean
Magic unsetter.
| Type | Description |
|---|---|
| string | Cache key |
NULL