mirror of
https://github.com/ruvnet/ruflo.git
synced 2026-11-23 21:59:14 +09:00
fix(memory): preserve frozen non-stateful invalidation patterns
Signed-off-by: Rudy Celekli <47457359+rudycelekli@users.noreply.github.com>
This commit is contained in:
2 files changed
+11
-2
No files matched your search
@@ -27,4 +27,12 @@ describe('stateful cache invalidation patterns', () => {
|
||||
expect(cache.invalidatePattern(pattern)).toBe(1);
|
||||
expect(pattern.lastIndex).toBe(4);
|
||||
});
|
||||
it('accepts a frozen non-global pattern without mutating its cursor', () => {
|
||||
const cache = new CacheManager<string>();
|
||||
caches.push(cache);
|
||||
cache.set('article-one', 'old');
|
||||
const pattern = Object.freeze(/article/);
|
||||
expect(cache.invalidatePattern(pattern)).toBe(1);
|
||||
expect(pattern.lastIndex).toBe(0);
|
||||
});
|
||||
});
|
||||
@@ -297,10 +297,11 @@ export class CacheManager<T = MemoryEntry> extends EventEmitter {
|
||||
|
||||
for (const key of this.cache.keys()) {
|
||||
// RegExp cursors belong to a single input, not the whole key sequence.
|
||||
const stateful = regex.global || regex.sticky;
|
||||
const lastIndex = regex.lastIndex;
|
||||
regex.lastIndex = 0;
|
||||
if (stateful) regex.lastIndex = 0;
|
||||
const matches = regex.test(key);
|
||||
regex.lastIndex = lastIndex;
|
||||
if (stateful) regex.lastIndex = lastIndex;
|
||||
if (matches) {
|
||||
this.delete(key);
|
||||
invalidated++;
|
||||
|
||||
Reference in new issue
Block a user