1
0
mirror of https://github.com/danog/dns.git synced 2024-12-12 09:29:46 +01:00
dns/lib/Addr/Cache/APCCache.php

62 lines
1.3 KiB
PHP
Raw Normal View History

<?php
namespace Addr\Cache;
use Addr\Cache;
class APCCache implements Cache
{
/**
* @param string $prefix A prefix to prepend to all keys.
*/
public function __construct($prefix = 'AddrCache\Cache\APCCache')
{
$this->prefix = $prefix;
}
/**
* Attempt to retrieve a value from the cache
*
* Returns an array [$cacheHit, $value]
* [true, $valueFromCache] - if it existed in the cache
* [false, null] - if it didn't already exist in the cache
*
* @param $name
* @return array
*/
public function get($name)
{
$name = $this->prefix . $name;
$value = apc_fetch($name, $success);
if ($success) {
return [true, $value];
}
return [false, null];
}
/**
* Stores a value in the cache. Overwrites the previous value if there was one.
*
* @param $name
* @param $value
* @param null $ttl
*/
public function store($name, $value, $ttl = null)
{
$name = $this->prefix . $name;
apc_store($name, $value, $ttl);
}
/**
* Deletes an entry from the cache.
* @param $name
*/
public function delete($name)
{
$name = $this->prefix . $name;
apc_delete($name);
}
}