Skip to content

Commit e0f3ba1

Browse files
committed
Merge #258 [backport 27]fix: Avoid clear cache with prefix [maybe needed for 28]
2 parents 140b50b + 6bcc2ad commit e0f3ba1

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
@@ -137,6 +137,11 @@ public function resolveReference(string $referenceId): ?IReference {
137137

138138
$reference = $matchedProvider->resolveReference($referenceId);
139139
if ($reference) {
140+
$cachePrefix = $matchedProvider->getCachePrefix($referenceId);
141+
if ($cachePrefix !== '') {
142+
// If a prefix is used we set an additional key to know when we need to delete by prefix during invalidateCache()
143+
$this->cache->set('hasPrefix-' . md5($cachePrefix), true, self::CACHE_TTL);
144+
}
140145
$this->cache->set($cacheKey, Reference::toCache($reference), self::CACHE_TTL);
141146
return $reference;
142147
}
@@ -190,11 +195,15 @@ private function getFullCacheKey(IReferenceProvider $provider, string $reference
190195
*/
191196
public function invalidateCache(string $cachePrefix, ?string $cacheKey = null): void {
192197
if ($cacheKey === null) {
193-
$this->cache->clear(md5($cachePrefix));
198+
// clear might be a heavy operation, so we only do it if there have actually been keys set
199+
if ($this->cache->remove('hasPrefix-' . md5($cachePrefix))) {
200+
$this->cache->clear(md5($cachePrefix));
201+
}
202+
194203
return;
195204
}
196205

197-
$this->cache->remove(md5($cachePrefix) . '-' . md5($cacheKey));
206+
$this->cache->remove(md5($cachePrefix) . '-' . md5($cacheKey ?? ''));
198207
}
199208

200209
/**

0 commit comments

Comments
 (0)