Skip to content

Commit 5eac383

Browse files
committed
Update AGENTS.md with common issues and implementation notes
1 parent 281b3f0 commit 5eac383

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

AGENTS.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,23 @@ Source code is in `src/`.
5555

5656
## Testing
5757

58-
- Framework: Mocha
58+
- Framework: Node.js built-in test runner (`node --test`)
5959
- Coverage: 100% (c8)
6060
- Test pattern: `tests/**/*.js`
6161
- 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

Comments
 (0)