1
0
mirror of https://github.com/danog/dns.git synced 2024-12-02 17:38:05 +01:00
dns/lib/Addr/Cache/APCCache.php
Chris Wright 585b5578e3 Cache refactoring
- pull $type back down into interface
 - remove delete() from interface
 - make get() async-capable
2014-07-22 02:54:23 +01:00

60 lines
1.3 KiB
PHP

<?php
namespace Addr\Cache;
class APCCache extends KeyValueCache
{
/**
* Constructor
*
* @param string $keyPrefix A prefix to prepend to all keys.
*/
public function __construct($keyPrefix = __CLASS__)
{
parent::__construct($keyPrefix);
}
/**
* Attempt to retrieve a value from the cache
*
* @param string $name
* @param int $type
* @param callable $callback
*/
public function get($name, $type, callable $callback)
{
$value = apc_fetch($this->generateKey($name, $type), $success);
if ($success) {
$callback(true, $value);
return;
}
$callback(false, null);
}
/**
* Stores a value in the cache. Overwrites the previous value if there was one.
*
* @param string $name
* @param int $type
* @param string $addr
* @param int $ttl
*/
public function store($name, $type, $addr, $ttl = null)
{
apc_store($this->generateKey($name, $type), $addr, $ttl);
}
/**
* Deletes an entry from the cache.
*
* @param string $name
* @param int $type
*/
public function delete($name, $type)
{
apc_delete($this->generateKey($name, $type));
}
}