1
0
mirror of https://github.com/danog/dns.git synced 2024-11-26 20:14:51 +01:00

Serialize cache entries, use stable versions where possible

This commit is contained in:
Niklas Keller 2017-06-17 08:31:35 +02:00
parent f06b5fd810
commit 3d035a7e14
2 changed files with 7 additions and 7 deletions

View File

@ -30,10 +30,10 @@
], ],
"require": { "require": {
"php": ">=7.0", "php": ">=7.0",
"amphp/amp": "^2.0", "amphp/amp": "^2",
"amphp/cache": "dev-amp_v2 as 0.2", "amphp/cache": "^1",
"amphp/file": "dev-amp_v2 as 0.2", "amphp/file": "dev-amp_v2 as 0.2",
"amphp/windows-registry": "dev-amp_v2 as 0.3", "amphp/windows-registry": "^0.3",
"daverandom/libdns": "^1" "daverandom/libdns": "^1"
}, },
"minimum-stability": "dev", "minimum-stability": "dev",

View File

@ -12,7 +12,7 @@ use LibDNS\Records\QuestionFactory;
class DefaultResolver implements Resolver { class DefaultResolver implements Resolver {
use CallableMaker; use CallableMaker;
private $messageFactory; private $messageFactory;
private $questionFactory; private $questionFactory;
private $encoder; private $encoder;
@ -236,7 +236,7 @@ class DefaultResolver implements Resolver {
$cacheValue = yield $this->arrayCache->get($cacheKey); $cacheValue = yield $this->arrayCache->get($cacheKey);
if ($cacheValue !== null) { if ($cacheValue !== null) {
$result[$type] = $cacheValue; $result[$type] = \json_decode($cacheValue, true);
unset($types[$k]); unset($types[$k]);
} }
} }
@ -630,7 +630,7 @@ class DefaultResolver implements Resolver {
$result[$record->getType()][] = [(string) $record->getData(), $record->getType(), $record->getTTL()]; $result[$record->getType()][] = [(string) $record->getData(), $record->getType(), $record->getTTL()];
} }
if (empty($result)) { if (empty($result)) {
$this->arrayCache->set("$name#$type", [], 300); // "it MUST NOT cache it for longer than five (5) minutes" per RFC 2308 section 7.1 $this->arrayCache->set("$name#$type", \json_encode([]), 300); // "it MUST NOT cache it for longer than five (5) minutes" per RFC 2308 section 7.1
$this->finalizeResult($serverId, $requestId, new NoRecordException( $this->finalizeResult($serverId, $requestId, new NoRecordException(
"No records returned for {$name}" "No records returned for {$name}"
)); ));
@ -665,7 +665,7 @@ class DefaultResolver implements Resolver {
$minttl = $ttl; $minttl = $ttl;
} }
} }
$this->arrayCache->set("$name#$type", $records, $minttl); $this->arrayCache->set("$name#$type", \json_encode($records), $minttl);
} }
$deferred->resolve($result); $deferred->resolve($result);
} }