Skip to content

Commit 4a122e2

Browse files
committed
DbEvict: standardize prefix matching
1 parent 91be9c1 commit 4a122e2

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ Note: you may refer to `README.md` for description of features.
33

44
## Dev (WIP)
55

6+
## 2.0.5
7+
- Improved database cache evictor handling of cache prefix
8+
- This should improve correctness
9+
610
## 2.0.4 (2025-07-06)
711
- Fixed database cache evictor "undefined property" warning (oops!)
812
- Fixed database cache evictor handling of cache prefix

src/Database/DatabaseEvictStrategy.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,17 @@ protected function yieldCacheTableItems(): \Generator
117117
$cachePrefix = $this->cachePrefix;
118118
// initialize the key to be just the cache prefix as the "zero string".
119119
$currentActualKey = $cachePrefix;
120+
$prefixLength = strlen($cachePrefix);
120121
// loop until no more items
121122
while (true) {
122123
// find the next key
124+
// note: different SQL flavors have different interpretations of LIKE, so we use SUBSTRING instead.
125+
// with SUBSTRING, we are clear we want a case-sensitive match, and we might potentially get collation-correct matching
123126
$record = $this->dbConn
124127
->table($this->dbTable)
125128
->select(['key', 'expiration', DB::raw('LENGTH(key) AS key_bytes'), DB::raw('LENGTH(value) AS value_bytes')])
126129
->where('key', '>', $currentActualKey)
127-
->where('key', 'LIKE', "$cachePrefix%")
130+
->where(DB::raw("SUBSTRING(key, 1, $prefixLength)"), '=', $cachePrefix)
128131
->limit(1)
129132
->first();
130133
if (!$record) {

0 commit comments

Comments
 (0)