You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: AGENTS.md
+17-1Lines changed: 17 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -55,7 +55,23 @@ Source code is in `src/`.
55
55
56
56
## Testing
57
57
58
-
- Framework: Mocha
58
+
- Framework: Node.js built-in test runner (`node --test`)
59
59
- Coverage: 100% (c8)
60
60
- Test pattern: `tests/**/*.js`
61
61
- All tests must pass with 100% coverage before merging
62
+
- Run: `npm test` (lint + tests)
63
+
64
+
## Common Issues to Avoid
65
+
66
+
-**Memory leaks**: When removing items from the linked list, always clear `prev`/`next` pointers to allow garbage collection
67
+
-**LRU order pollution**: Methods like `entries()` and `values()` should access items directly rather than calling `get()`, which moves items and can delete expired items mid-iteration
68
+
-**TTL edge cases**: Direct property access (`this.items[key]`) should be used instead of `has()` when you need to inspect expired-but-not-yet-deleted items
69
+
-**Dead code**: Always verify edge case code is actually reachable before adding special handling
70
+
-**Constructor assignment**: Use `let` not `const` for variables that may be reassigned (e.g., in `setWithEvicted`)
71
+
72
+
## Implementation Notes
73
+
74
+
- The LRU uses a doubly-linked list with `first` and `last` pointers for O(1) operations
75
+
- TTL is stored per-item as an `expiry` timestamp; `0` means no expiration
76
+
-`moveToEnd()` is the core method for maintaining LRU order - item is always moved to the `last` position
77
+
-`setWithEvicted()` optimizes updates by avoiding the full `set()` path for existing keys
0 commit comments