From 3d035a7e147fad557639ce296647b9bb35b439f2 Mon Sep 17 00:00:00 2001 From: Niklas Keller Date: Sat, 17 Jun 2017 08:31:35 +0200 Subject: [PATCH] Serialize cache entries, use stable versions where possible --- composer.json | 6 +++--- lib/DefaultResolver.php | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/composer.json b/composer.json index 7621e50..860be38 100644 --- a/composer.json +++ b/composer.json @@ -30,10 +30,10 @@ ], "require": { "php": ">=7.0", - "amphp/amp": "^2.0", - "amphp/cache": "dev-amp_v2 as 0.2", + "amphp/amp": "^2", + "amphp/cache": "^1", "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" }, "minimum-stability": "dev", diff --git a/lib/DefaultResolver.php b/lib/DefaultResolver.php index dfdf10c..4a3a7e3 100644 --- a/lib/DefaultResolver.php +++ b/lib/DefaultResolver.php @@ -12,7 +12,7 @@ use LibDNS\Records\QuestionFactory; class DefaultResolver implements Resolver { use CallableMaker; - + private $messageFactory; private $questionFactory; private $encoder; @@ -236,7 +236,7 @@ class DefaultResolver implements Resolver { $cacheValue = yield $this->arrayCache->get($cacheKey); if ($cacheValue !== null) { - $result[$type] = $cacheValue; + $result[$type] = \json_decode($cacheValue, true); unset($types[$k]); } } @@ -630,7 +630,7 @@ class DefaultResolver implements Resolver { $result[$record->getType()][] = [(string) $record->getData(), $record->getType(), $record->getTTL()]; } 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( "No records returned for {$name}" )); @@ -665,7 +665,7 @@ class DefaultResolver implements Resolver { $minttl = $ttl; } } - $this->arrayCache->set("$name#$type", $records, $minttl); + $this->arrayCache->set("$name#$type", \json_encode($records), $minttl); } $deferred->resolve($result); }