1
0
mirror of https://github.com/danog/dns.git synced 2025-01-22 21:41:11 +01:00

Merge pull request #17 from DaveRandom/fix/cached-null-address

Cached null value checks
This commit is contained in:
Chris Wright 2014-11-26 15:47:49 +00:00
commit 2a8e46babc
4 changed files with 27 additions and 4 deletions

View File

@ -4,6 +4,11 @@ namespace Amp\Dns;
interface Cache {
/**
* Default time-to-live - 1 hour
*/
const DEFAULT_TTL = 3600;
/**
* Attempt to retrieve a value from the cache
*

View File

@ -43,6 +43,14 @@ class APCCache extends KeyValueCache
*/
public function store($name, $type, $addr, $ttl = null)
{
if ($addr === null) {
throw new \InvalidArgumentException('Caching null addresses is disallowed');
}
if ($ttl === null) {
$ttl = self::DEFAULT_TTL;
}
apc_store($this->generateKey($name, $type), $addr, $ttl);
}

View File

@ -5,10 +5,6 @@ namespace Amp\Dns\Cache;
use Amp\Dns\Cache;
class MemoryCache implements Cache {
/**
* Default time-to-live - 1 day
*/
const DEFAULT_TTL = 86400;
/**
* Internal data store for cache values
@ -32,6 +28,8 @@ class MemoryCache implements Cache {
$callback(true, $value);
return;
}
unset($this->recordsByTypeAndName[$type][$name]);
}
$callback(false, null);
@ -46,6 +44,10 @@ class MemoryCache implements Cache {
* @param int $ttl
*/
public function store($name, $type, $addr, $ttl = null) {
if ($addr === null) {
throw new \InvalidArgumentException('Caching null addresses is disallowed');
}
if ($ttl === null) {
$ttl = self::DEFAULT_TTL;
}

View File

@ -65,6 +65,14 @@ SCRIPT;
* @param int $ttl
*/
public function store($name, $type, $addr, $ttl = null) {
if ($addr === null) {
throw new \InvalidArgumentException('Caching null addresses is disallowed');
}
if ($ttl === null) {
$ttl = self::DEFAULT_TTL;
}
$key = $this->generateKey($name, $type);
if ($ttl > 0) {