From 3a51eaa0103e219501fb2d7c5c810f29da450e04 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 17 Apr 2026 13:52:53 +1200 Subject: [PATCH] fix: wrap cache purge operations in try-catch for graceful degradation Cache purge failures should not propagate exceptions up the stack and cause HTTP request failures. This matches the existing pattern for cache load and save operations which already use try-catch with warning logging. When cache is slow or unavailable, purge operations now: - Log a warning message instead of throwing - Allow the request to continue successfully - Prevent cascading failures during cache infrastructure issues Co-Authored-By: Claude Opus 4.5 --- src/Database/Database.php | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/Database/Database.php b/src/Database/Database.php index bae99ae79..a05fb842a 100644 --- a/src/Database/Database.php +++ b/src/Database/Database.php @@ -8214,12 +8214,16 @@ public function purgeCachedCollection(string $collectionId): bool { [$collectionKey] = $this->getCacheKeys($collectionId); - $documentKeys = $this->cache->list($collectionKey); - foreach ($documentKeys as $documentKey) { - $this->cache->purge($documentKey); - } + try { + $documentKeys = $this->cache->list($collectionKey); + foreach ($documentKeys as $documentKey) { + $this->cache->purge($documentKey); + } - $this->cache->purge($collectionKey); + $this->cache->purge($collectionKey); + } catch (Exception $e) { + Console::warning('Failed to purge collection from cache: ' . $e->getMessage()); + } return true; } @@ -8241,8 +8245,12 @@ protected function purgeCachedDocumentInternal(string $collectionId, ?string $id [$collectionKey, $documentKey] = $this->getCacheKeys($collectionId, $id); - $this->cache->purge($collectionKey, $documentKey); - $this->cache->purge($documentKey); + try { + $this->cache->purge($collectionKey, $documentKey); + $this->cache->purge($documentKey); + } catch (Exception $e) { + Console::warning('Failed to purge document from cache: ' . $e->getMessage()); + } return true; }