From de42073a963557cc55736d984a6950d802b6ea67 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Tue, 23 Jun 2026 22:31:34 +1200 Subject: [PATCH] fix(cache): hide the reserved generation field from list() list() (hKeys) would surface the internal __utopia_gen__ field as a listable cache field, leaking the lease internals to callers. Filter it out so the reserved field is fully invisible to the public API. Covered by a test. Co-Authored-By: Claude Opus 4.8 --- src/Cache/Adapter/Redis.php | 3 ++- tests/Cache/E2E/Redis/LeasableTest.php | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Cache/Adapter/Redis.php b/src/Cache/Adapter/Redis.php index 1df8d119d3..67dd8ee979 100644 --- a/src/Cache/Adapter/Redis.php +++ b/src/Cache/Adapter/Redis.php @@ -277,7 +277,8 @@ class Redis implements Adapter, Leasable, Retryable return []; } - return $keys; + // Don't expose the internal generation field as a listable cache field. + return \array_values(\array_filter($keys, fn (string $field): bool => $field !== self::GENERATION_FIELD)); } /** diff --git a/tests/Cache/E2E/Redis/LeasableTest.php b/tests/Cache/E2E/Redis/LeasableTest.php index e2ae7389a7..187c352131 100644 --- a/tests/Cache/E2E/Redis/LeasableTest.php +++ b/tests/Cache/E2E/Redis/LeasableTest.php @@ -113,4 +113,16 @@ class LeasableTest extends TestCase $this->assertSame('1', $this->cache->getGeneration('doc:1')); $this->assertFalse($this->cache->saveWithLease('doc:1', 'stale', 'doc:1', '0')); } + + public function testListHidesGenerationField(): void + { + $this->cache->flush(); + $this->cache->saveWithLease('doc:1', ['v' => 1], 'field-a', $this->cache->getGeneration('doc:1')); + $this->assertSame(['field-a'], $this->cache->list('doc:1')); + + // After a purge the key holds only its internal generation field, which + // must not surface as a listable cache field. + $this->cache->purge('doc:1'); + $this->assertSame([], $this->cache->list('doc:1')); + } }