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 <noreply@anthropic.com>
This commit is contained in:
Jake BarnbyandClaude Opus 4.8 committed 2026-06-23 22:31:34 +12:00
1 parent 6f0557b42a
commit de42073a96
2 files changed
+14 -1

No files matched your search

+2 -1
View File
@@ -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));
}
/**
+12
View File
@@ -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'));
}
}