Skip to content

Commit

Permalink
Merge pull request #44078 from nextcloud/backport/43992/stable26
Browse files Browse the repository at this point in the history
[stable26] fix: Avoid clear cache with prefix
  • Loading branch information
susnux authored Mar 8, 2024
2 parents d15d61a + 2160260 commit fead154
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/private/Collaboration/Reference/ReferenceManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,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;
}
Expand Down Expand Up @@ -190,7 +195,11 @@ 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;
}

Expand Down

0 comments on commit fead154

Please sign in to comment.