From 78397432eae0f9f53eb7d8354f3bc0d38105f340 Mon Sep 17 00:00:00 2001 From: "szabolcs.gyuris" Date: Tue, 12 Mar 2024 09:18:27 +0000 Subject: [PATCH] [backport 27]fix: Avoid clear cache with prefix [maybe needed for 28] (cherry picked from commit 6bcc2ad86d476f8b90f3c664edf22751c8c9b27e) --- .../Collaboration/Reference/ReferenceManager.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/private/Collaboration/Reference/ReferenceManager.php b/lib/private/Collaboration/Reference/ReferenceManager.php index 1db87a5649461..06f7ccc66bb5c 100644 --- a/lib/private/Collaboration/Reference/ReferenceManager.php +++ b/lib/private/Collaboration/Reference/ReferenceManager.php @@ -117,6 +117,11 @@ public function resolveReference(string $referenceId): ?IReference { $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; } @@ -161,11 +166,15 @@ private function getFullCacheKey(IReferenceProvider $provider, string $reference */ 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; } - $this->cache->remove(md5($cachePrefix) . '-' . md5($cacheKey)); + $this->cache->remove(md5($cachePrefix) . '-' . md5($cacheKey ?? '')); } /**