Merge pull request #44078 from nextcloud/backport/43992/stable26

[stable26] fix: Avoid clear cache with prefix
This commit is contained in:
Ferdinand Thiessen 2024-03-08 10:57:37 +01:00 committed by GitHub
commit fead154fc1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -137,6 +137,11 @@ class ReferenceManager implements IReferenceManager {
$reference = $matchedProvider->resolveReference($referenceId);
if ($reference) {
$cachePrefix = $matchedProvider->getCachePrefix($referenceId);
if ($cachePrefix !== '') {
// If a prefix is used we set an additional key to know when we need to delete by prefix during invalidateCache()
$this->cache->set('hasPrefix-' . md5($cachePrefix), true, self::CACHE_TTL);
}
$this->cache->set($cacheKey, Reference::toCache($reference), self::CACHE_TTL);
return $reference;
}
@ -190,7 +195,11 @@ class ReferenceManager implements IReferenceManager {
*/
public function invalidateCache(string $cachePrefix, ?string $cacheKey = null): void {
if ($cacheKey === null) {
$this->cache->clear(md5($cachePrefix));
// clear might be a heavy operation, so we only do it if there have actually been keys set
if ($this->cache->remove('hasPrefix-' . md5($cachePrefix))) {
$this->cache->clear(md5($cachePrefix));
}
return;
}