Skip to content

Commit

Permalink
Cache invalidation: Restore non-breaking signature on Cache remember …
Browse files Browse the repository at this point in the history
…method
  • Loading branch information
jon48 committed Feb 27, 2021
1 parent eb59f3b commit 2104542
Show file tree
Hide file tree
Showing 20 changed files with 24 additions and 23 deletions.
4 changes: 2 additions & 2 deletions app/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion app/Factories/AbstractGedcomRecordFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()]);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/Factories/FamilyFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()]);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/Factories/GedcomRecordFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()]);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/Factories/HeaderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()]);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/Factories/ImageFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion app/Factories/IndividualFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()]);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/Factories/LocationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()]);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/Factories/MediaFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()]);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/Factories/NoteFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()]);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/Factories/RepositoryFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()]);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/Factories/SourceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()]);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/Factories/SubmissionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()]);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/Factories/SubmitterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()]);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/GedcomRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Middleware/BadBotBlocker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

/**
Expand Down
3 changes: 2 additions & 1 deletion app/Module/MediaTabModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]
);
}
Expand Down
2 changes: 1 addition & 1 deletion app/Module/ModuleCustomTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function customModuleLatestVersion(): string
}

return $this->customModuleVersion();
}, [], 86400);
}, 86400);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions app/Module/SiteMapModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
4 changes: 2 additions & 2 deletions tests/app/CacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down

0 comments on commit 2104542

Please sign in to comment.