Skip to content

Commit b6691b3

Browse files
authored
Merge pull request #43992 from nextcloud/fix/avoid-cache-clear
fix: Avoid clear cache with prefix
2 parents 3406908 + 972a611 commit b6691b3

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

lib/private/Collaboration/Reference/ReferenceManager.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ public function resolveReference(string $referenceId): ?IReference {
117117

118118
$reference = $matchedProvider->resolveReference($referenceId);
119119
if ($reference) {
120+
$cachePrefix = $matchedProvider->getCachePrefix($referenceId);
121+
if ($cachePrefix !== '') {
122+
// If a prefix is used we set an additional key to know when we need to delete by prefix during invalidateCache()
123+
$this->cache->set('hasPrefix-' . md5($cachePrefix), true, self::CACHE_TTL);
124+
}
120125
$this->cache->set($cacheKey, Reference::toCache($reference), self::CACHE_TTL);
121126
return $reference;
122127
}
@@ -161,7 +166,11 @@ private function getFullCacheKey(IReferenceProvider $provider, string $reference
161166
*/
162167
public function invalidateCache(string $cachePrefix, ?string $cacheKey = null): void {
163168
if ($cacheKey === null) {
164-
$this->cache->clear(md5($cachePrefix));
169+
// clear might be a heavy operation, so we only do it if there have actually been keys set
170+
if ($this->cache->remove('hasPrefix-' . md5($cachePrefix))) {
171+
$this->cache->clear(md5($cachePrefix));
172+
}
173+
165174
return;
166175
}
167176

0 commit comments

Comments
 (0)