From 8a51715eff1180e796f138dcae9a2614f159865e Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Tue, 5 May 2026 19:29:07 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B9=20Remove=20dead=20cleanup=20method?= =?UTF-8?q?=20in=20MemoryCacheBackend?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit removes the `cleanup()` method from `MemoryCacheBackend` and its corresponding test case. The method was identified as dead code since it wasn't part of the `CacheBackend` interface and was only used within its own tests. Expiration is already handled lazily within the `get()` method. 🎯 What: Removed dead `cleanup()` method from `src/backends/memory.ts` and associated test. 💡 Why: Improve maintainability and readability by removing unused code. ✅ Verification: Confirmed no other parts of the codebase depend on this method. ✨ Result: Cleaner implementation of `MemoryCacheBackend`. Co-authored-by: suranig <24814104+suranig@users.noreply.github.com> --- src/backends/memory.ts | 21 --------------------- test/backends/memory.test.ts | 15 --------------- 2 files changed, 36 deletions(-) diff --git a/src/backends/memory.ts b/src/backends/memory.ts index 7d0a88c..9c3cc36 100644 --- a/src/backends/memory.ts +++ b/src/backends/memory.ts @@ -80,25 +80,4 @@ export class MemoryCacheBackend implements CacheBackend { this.store.clear(); this.locks.clear(); } - - /** - * Clean up expired entries (useful for memory management). - */ - cleanup(): void { - const now = Date.now(); - - // Clean up expired cache entries - for (const [key, item] of this.store.entries()) { - if (item.expiresAt && item.expiresAt <= now) { - this.store.delete(key); - } - } - - // Clean up expired locks - for (const [key, lock] of this.locks.entries()) { - if (lock.expiresAt <= now) { - this.locks.delete(key); - } - } - } } diff --git a/test/backends/memory.test.ts b/test/backends/memory.test.ts index 03dd7ca..a34af72 100644 --- a/test/backends/memory.test.ts +++ b/test/backends/memory.test.ts @@ -77,19 +77,4 @@ describe('MemoryCacheBackend', () => { expect(await backend.get('key2')).toBeUndefined(); expect(await backend.lock('lock1', 1)).toBe(true); // Lock should be cleared }); - - it('should cleanup expired entries', async () => { - await backend.set('expired-key', 42, { ttl: 0.1 }); - await backend.lock('expired-lock', 0.1); - - // Wait for expiration - await new Promise((resolve) => setTimeout(resolve, 150)); - - // Manually trigger cleanup - backend.cleanup(); - - // Should not be able to acquire the expired lock - const lockAcquired = await backend.lock('expired-lock', 1); - expect(lockAcquired).toBe(true); - }); });