From 121444cd5faaa1136f62e264bd82a4c75438aabb Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Mon, 11 May 2026 16:09:58 +0400 Subject: [PATCH] perf(storage): refresh streamed cache hits with touch --- app/controllers/shared/api.php | 13 +------------ composer.lock | 12 ++++++------ 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index 1485688162..9c9f747812 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -714,18 +714,13 @@ Http::init() } } - $cachedPayload = null; $accessedAt = $cacheLog->getAttribute('accessedAt', ''); if (DateTime::formatTz(DateTime::addSeconds(new \DateTime(), -APP_CACHE_UPDATE)) > $accessedAt) { $authorization->skip(fn () => $dbForProject->updateDocument('cache', $cacheLog->getId(), new Document([ 'accessedAt' => DateTime::now(), ]))); - $cachedPayload = \stream_get_contents($data); - if ($cachedPayload === false) { - throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Failed to read cached response stream'); - } // Refresh the filesystem file's mtime so TTL-based expiry in cache->load() stays valid - $cache->save($key, $cachedPayload); + $cache->touch($key); } $response @@ -735,12 +730,6 @@ Http::init() $storageCacheOperationsCounter->add(1, ['result' => 'hit']); if (! $isImageTransformation || ! $isDisabled) { Span::add('storage.cache.hit', true); - if ($cachedPayload !== null) { - \fclose($data); - $response->send($cachedPayload); - return; - } - try { while (! \feof($data)) { $chunk = \fread($data, MAX_OUTPUT_CHUNK_SIZE); diff --git a/composer.lock b/composer.lock index 0aa58ca03e..657e89dabd 100644 --- a/composer.lock +++ b/composer.lock @@ -3614,16 +3614,16 @@ }, { "name": "utopia-php/cache", - "version": "1.0.2", + "version": "1.0.3", "source": { "type": "git", "url": "https://github.com/utopia-php/cache.git", - "reference": "d36f9050c39c02e09a7763389c9e71258e74af1f" + "reference": "ef52a04e8bfa314c621e3d3326ffcf50db3dfdfa" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/cache/zipball/d36f9050c39c02e09a7763389c9e71258e74af1f", - "reference": "d36f9050c39c02e09a7763389c9e71258e74af1f", + "url": "https://api.github.com/repos/utopia-php/cache/zipball/ef52a04e8bfa314c621e3d3326ffcf50db3dfdfa", + "reference": "ef52a04e8bfa314c621e3d3326ffcf50db3dfdfa", "shasum": "" }, "require": { @@ -3660,9 +3660,9 @@ ], "support": { "issues": "https://github.com/utopia-php/cache/issues", - "source": "https://github.com/utopia-php/cache/tree/1.0.2" + "source": "https://github.com/utopia-php/cache/tree/1.0.3" }, - "time": "2026-05-08T11:40:20+00:00" + "time": "2026-05-11T11:02:13+00:00" }, { "name": "utopia-php/cli",