From 210454254cd7d530cd9de96cd109772ea65e1c96 Mon Sep 17 00:00:00 2001 From: Jonathan Jaubart Date: Sat, 27 Feb 2021 13:42:01 +0000 Subject: [PATCH] Cache invalidation: Restore non-breaking signature on Cache remember method --- app/Cache.php | 4 ++-- app/Factories/AbstractGedcomRecordFactory.php | 2 +- app/Factories/FamilyFactory.php | 2 +- app/Factories/GedcomRecordFactory.php | 2 +- app/Factories/HeaderFactory.php | 2 +- app/Factories/ImageFactory.php | 2 +- app/Factories/IndividualFactory.php | 2 +- app/Factories/LocationFactory.php | 2 +- app/Factories/MediaFactory.php | 2 +- app/Factories/NoteFactory.php | 2 +- app/Factories/RepositoryFactory.php | 2 +- app/Factories/SourceFactory.php | 2 +- app/Factories/SubmissionFactory.php | 2 +- app/Factories/SubmitterFactory.php | 2 +- app/GedcomRecord.php | 2 +- app/Http/Middleware/BadBotBlocker.php | 2 +- app/Module/MediaTabModule.php | 3 ++- app/Module/ModuleCustomTrait.php | 2 +- app/Module/SiteMapModule.php | 4 ++-- tests/app/CacheTest.php | 4 ++-- 20 files changed, 24 insertions(+), 23 deletions(-) diff --git a/app/Cache.php b/app/Cache.php index 76131c10f91..6b2b041aa13 100644 --- a/app/Cache.php +++ b/app/Cache.php @@ -59,12 +59,12 @@ public function safeKey(string $key): string * * @param string $key * @param Closure $closure - * @param string[] $tags * @param int|null $ttl + * @param string[] $tags * * @return mixed */ - public function remember(string $key, Closure $closure, array $tags = [], int $ttl = null) + public function remember(string $key, Closure $closure, int $ttl = null, array $tags = []) { $tags = array_map([$this, 'safeKey'], $tags); return $this->cache->get( diff --git a/app/Factories/AbstractGedcomRecordFactory.php b/app/Factories/AbstractGedcomRecordFactory.php index 9246bd1bd95..171bc30255b 100644 --- a/app/Factories/AbstractGedcomRecordFactory.php +++ b/app/Factories/AbstractGedcomRecordFactory.php @@ -59,7 +59,7 @@ protected function pendingChanges(Tree $tree): Collection ->where('status', '=', 'pending') ->orderBy('change_id') ->pluck('new_gedcom', 'xref'); - }, ['pending-t-' . $tree->id()]); + }, null, ['pending-t-' . $tree->id()]); } /** diff --git a/app/Factories/FamilyFactory.php b/app/Factories/FamilyFactory.php index 1c3ab7cf47d..dff3d2fdba3 100644 --- a/app/Factories/FamilyFactory.php +++ b/app/Factories/FamilyFactory.php @@ -68,7 +68,7 @@ public function make(string $xref, Tree $tree, string $gedcom = null): ?Family ->map(Registry::individualFactory()->mapper($tree)); return new Family($xref, $gedcom ?? '', $pending, $tree); - }, ['gedrec-' . $xref . '@' . $tree->id()]); + }, null, ['gedrec-' . $xref . '@' . $tree->id()]); } /** diff --git a/app/Factories/GedcomRecordFactory.php b/app/Factories/GedcomRecordFactory.php index 2c751048748..e33ae357072 100644 --- a/app/Factories/GedcomRecordFactory.php +++ b/app/Factories/GedcomRecordFactory.php @@ -108,7 +108,7 @@ public function make(string $xref, Tree $tree, string $gedcom = null): ?GedcomRe $type = $this->extractType($gedcom ?? $pending); return $this->newGedcomRecord($type, $xref, $gedcom ?? '', $pending, $tree); - }, ['gedrec-' . $xref . '@' . $tree->id()]); + }, null, ['gedrec-' . $xref . '@' . $tree->id()]); } /** diff --git a/app/Factories/HeaderFactory.php b/app/Factories/HeaderFactory.php index 0622592d7de..4b70e2f5d38 100644 --- a/app/Factories/HeaderFactory.php +++ b/app/Factories/HeaderFactory.php @@ -59,7 +59,7 @@ public function make(string $xref, Tree $tree, string $gedcom = null): ?Header $xref = $this->extractXref($gedcom ?? $pending, $xref); return new Header($xref, $gedcom ?? '', $pending, $tree); - }, ['gedrec-' . $xref . '@' . $tree->id()]); + }, null, ['gedrec-' . $xref . '@' . $tree->id()]); } /** diff --git a/app/Factories/ImageFactory.php b/app/Factories/ImageFactory.php index a59295819a1..c8f5e82ec72 100644 --- a/app/Factories/ImageFactory.php +++ b/app/Factories/ImageFactory.php @@ -239,7 +239,7 @@ public function mediaFileThumbnailResponse( // Images and Responses both contain resources - which cannot be serialized. // So cache the raw image data. - $data = Registry::cache()->file()->remember($key, $closure, [], static::THUMBNAIL_CACHE_TTL); + $data = Registry::cache()->file()->remember($key, $closure, static::THUMBNAIL_CACHE_TTL); return $this->imageResponse($data, $mime_type, ''); } catch (NotReadableException $ex) { diff --git a/app/Factories/IndividualFactory.php b/app/Factories/IndividualFactory.php index e08b90156f1..c36b38d7326 100644 --- a/app/Factories/IndividualFactory.php +++ b/app/Factories/IndividualFactory.php @@ -58,7 +58,7 @@ public function make(string $xref, Tree $tree, string $gedcom = null): ?Individu $xref = $this->extractXref($gedcom ?? $pending, $xref); return new Individual($xref, $gedcom ?? '', $pending, $tree); - }, ['gedrec-' . $xref . '@' . $tree->id()]); + }, null, ['gedrec-' . $xref . '@' . $tree->id()]); } /** diff --git a/app/Factories/LocationFactory.php b/app/Factories/LocationFactory.php index 9c1e69cf777..8df412dc71e 100644 --- a/app/Factories/LocationFactory.php +++ b/app/Factories/LocationFactory.php @@ -59,7 +59,7 @@ public function make(string $xref, Tree $tree, string $gedcom = null): ?Location $xref = $this->extractXref($gedcom ?? $pending, $xref); return new Location($xref, $gedcom ?? '', $pending, $tree); - }, ['gedrec-' . $xref . '@' . $tree->id()]); + }, null, ['gedrec-' . $xref . '@' . $tree->id()]); } /** diff --git a/app/Factories/MediaFactory.php b/app/Factories/MediaFactory.php index e1cf520574a..d081c420300 100644 --- a/app/Factories/MediaFactory.php +++ b/app/Factories/MediaFactory.php @@ -59,7 +59,7 @@ public function make(string $xref, Tree $tree, string $gedcom = null): ?Media $xref = $this->extractXref($gedcom ?? $pending, $xref); return new Media($xref, $gedcom ?? '', $pending, $tree); - }, ['gedrec-' . $xref . '@' . $tree->id()]); + }, null, ['gedrec-' . $xref . '@' . $tree->id()]); } /** diff --git a/app/Factories/NoteFactory.php b/app/Factories/NoteFactory.php index 7c4c4df5419..4a14b6bd489 100644 --- a/app/Factories/NoteFactory.php +++ b/app/Factories/NoteFactory.php @@ -59,7 +59,7 @@ public function make(string $xref, Tree $tree, string $gedcom = null): ?Note $xref = $this->extractXref($gedcom ?? $pending, $xref); return new Note($xref, $gedcom ?? '', $pending, $tree); - }, ['gedrec-' . $xref . '@' . $tree->id()]); + }, null, ['gedrec-' . $xref . '@' . $tree->id()]); } /** diff --git a/app/Factories/RepositoryFactory.php b/app/Factories/RepositoryFactory.php index 4c9000ba665..d48198f19c5 100644 --- a/app/Factories/RepositoryFactory.php +++ b/app/Factories/RepositoryFactory.php @@ -59,7 +59,7 @@ public function make(string $xref, Tree $tree, string $gedcom = null): ?Reposito $xref = $this->extractXref($gedcom ?? $pending, $xref); return new Repository($xref, $gedcom ?? '', $pending, $tree); - }, ['gedrec-' . $xref . '@' . $tree->id()]); + }, null, ['gedrec-' . $xref . '@' . $tree->id()]); } /** diff --git a/app/Factories/SourceFactory.php b/app/Factories/SourceFactory.php index 3c14e0578de..c89b7954f24 100644 --- a/app/Factories/SourceFactory.php +++ b/app/Factories/SourceFactory.php @@ -60,7 +60,7 @@ public function make(string $xref, Tree $tree, string $gedcom = null): ?Source $xref = $this->extractXref($gedcom ?? $pending, $xref); return new Source($xref, $gedcom ?? '', $pending, $tree); - }, ['gedrec-' . $xref . '@' . $tree->id()]); + }, null, ['gedrec-' . $xref . '@' . $tree->id()]); } /** diff --git a/app/Factories/SubmissionFactory.php b/app/Factories/SubmissionFactory.php index de7e4f6c668..16366ccaf45 100644 --- a/app/Factories/SubmissionFactory.php +++ b/app/Factories/SubmissionFactory.php @@ -59,7 +59,7 @@ public function make(string $xref, Tree $tree, string $gedcom = null): ?Submissi $xref = $this->extractXref($gedcom ?? $pending, $xref); return new Submission($xref, $gedcom ?? '', $pending, $tree); - }, ['gedrec-' . $xref . '@' . $tree->id()]); + }, null, ['gedrec-' . $xref . '@' . $tree->id()]); } /** diff --git a/app/Factories/SubmitterFactory.php b/app/Factories/SubmitterFactory.php index f9d9177c48e..7d58960e2e7 100644 --- a/app/Factories/SubmitterFactory.php +++ b/app/Factories/SubmitterFactory.php @@ -59,7 +59,7 @@ public function make(string $xref, Tree $tree, string $gedcom = null): ?Submitte $xref = $this->extractXref($gedcom ?? $pending, $xref); return new Submitter($xref, $gedcom ?? '', $pending, $tree); - }, ['gedrec-' . $xref . '@' . $tree->id()]); + }, null, ['gedrec-' . $xref . '@' . $tree->id()]); } /** diff --git a/app/GedcomRecord.php b/app/GedcomRecord.php index d3598789fb8..9e66b1adbbe 100644 --- a/app/GedcomRecord.php +++ b/app/GedcomRecord.php @@ -315,7 +315,7 @@ public function canShow(int $access_level = null): bool return Registry::cache()->array()->remember($cache_key, function () use ($access_level) { return $this->canShowRecord($access_level); - }, ['gedrec-' . $this->tree->id() . '-' . $this->xref]); + }, null, ['gedrec-' . $this->tree->id() . '-' . $this->xref]); } /** diff --git a/app/Http/Middleware/BadBotBlocker.php b/app/Http/Middleware/BadBotBlocker.php index cd98d533965..eb70856ea30 100644 --- a/app/Http/Middleware/BadBotBlocker.php +++ b/app/Http/Middleware/BadBotBlocker.php @@ -266,7 +266,7 @@ private function fetchIpRangesForAsn(string $asn): array } catch (Throwable $ex) { return []; } - }, [], random_int(self::WHOIS_TTL_MIN, self::WHOIS_TTL_MAX)); + }, random_int(self::WHOIS_TTL_MIN, self::WHOIS_TTL_MAX)); } /** diff --git a/app/Module/MediaTabModule.php b/app/Module/MediaTabModule.php index 03e8c2ed0b7..b996e35639f 100644 --- a/app/Module/MediaTabModule.php +++ b/app/Module/MediaTabModule.php @@ -146,10 +146,11 @@ static function () use ($individual): Collection { $facts = $facts->filter(static function (Fact $fact): bool { return preg_match('/(?:^1|\n\d) OBJE @' . Gedcom::REGEX_XREF . '@/', $fact->gedcom()) === 1; - }, []); + }); return Fact::sortFacts($facts); }, + null, ['gedrec-' . $cacheTag] ); } diff --git a/app/Module/ModuleCustomTrait.php b/app/Module/ModuleCustomTrait.php index 19e1b83a8e8..294e4fd06a8 100644 --- a/app/Module/ModuleCustomTrait.php +++ b/app/Module/ModuleCustomTrait.php @@ -101,7 +101,7 @@ public function customModuleLatestVersion(): string } return $this->customModuleVersion(); - }, [], 86400); + }, 86400); } /** diff --git a/app/Module/SiteMapModule.php b/app/Module/SiteMapModule.php index 9cef15ef2aa..3b76b5c332a 100644 --- a/app/Module/SiteMapModule.php +++ b/app/Module/SiteMapModule.php @@ -292,7 +292,7 @@ private function siteMapIndex(ServerRequestInterface $request): ResponseInterfac 'records_per_volume' => self::RECORDS_PER_VOLUME, 'sitemap_xsl' => route('sitemap-style'), ]); - }, [], self::CACHE_LIFE); + }, self::CACHE_LIFE); return response($content, StatusCodeInterface::STATUS_OK, [ 'Content-Type' => 'application/xml', @@ -327,7 +327,7 @@ private function siteMapFile(ServerRequestInterface $request): ResponseInterface 'sitemap_xsl' => route('sitemap-style'), 'tree' => $tree, ]); - }, [], self::CACHE_LIFE); + }, self::CACHE_LIFE); return response($content, StatusCodeInterface::STATUS_OK, [ 'Content-Type' => 'application/xml', diff --git a/tests/app/CacheTest.php b/tests/app/CacheTest.php index c8954883808..db702293109 100644 --- a/tests/app/CacheTest.php +++ b/tests/app/CacheTest.php @@ -112,7 +112,7 @@ public function testRememberWithTTL(): void { self::assertEquals(10, $this->cache->remember('test', function () { return 10; - }, [], 1)); + }, 1, [])); self::assertTrue($this->tagAwareAdapter->hasItem($this->cache->safeKey('test'))); sleep(2); @@ -128,7 +128,7 @@ public function testInvalidateTags(): void { self::assertEquals(10, $this->cache->remember('test', function () { return 10; - }, ['test-tag'])); + }, null, ['test-tag'])); self::assertTrue($this->cache->invalidateTags(['test-tag'])); self::assertEquals(15, $this->cache->remember('test', function () { return 15;