Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions src/backends/memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,25 +80,4 @@ export class MemoryCacheBackend<T = unknown> implements CacheBackend<T> {
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);
}
}
}
}
15 changes: 0 additions & 15 deletions test/backends/memory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
Loading