Skip to content

Commit 5a16d88

Browse files
committed
Merge #261 [backport 28]fix: Avoid clear cache with prefix [maybe needed for 29]
2 parents 8301d08 + 7839743 commit 5a16d88

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

lib/private/Collaboration/Reference/ReferenceManager.php

Lines changed: 11 additions & 2 deletions
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,11 +166,15 @@ 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

168-
$this->cache->remove(md5($cachePrefix) . '-' . md5($cacheKey));
177+
$this->cache->remove(md5($cachePrefix) . '-' . md5($cacheKey ?? ''));
169178
}
170179

171180
/**

0 commit comments

Comments
 (0)