feat(cache-map): Promote makeLRUCacheMap into a new package
Description
- Introduce
@endo/cache-map. - Remove "LRU" eviction policy constraint (but keep that as the actual current implementation).
- Support opting in to strongly-held keys (to be used in agoric-sdk for caching string-keyed board mappings).
- Add a
getMetrics()facet for evaluating cache efficiency (currently rudimentary).
Security Considerations
This package sits beneath SES, and so must be defensive without relying upon harden/assert/etc.
Scaling Considerations
The implementation remains a doubly-linked ring with permanent head and LRU eviction policy. All operations are O(1), mutating up to five nodes for promotion/insertion/removal (the target node and its former and new neighbors) but minimizing that when possible (e.g., bailing out early in moveCellAfter when the target is already in the right position). Cells are created up to the specified capacity and never destroyed, although their single-entry weak maps are necessarily replaced when evicting a tail in set. Cells are currently created lazily, although that could be made eager for better memory locality (probably with a boolean lazy option for opting out). All in all, it's probably about as good as an object-based implementation can be (and a bit better than the makeLRUCacheMap from which it is derived).
Documentation Considerations
Includes a README.md with explanation and example usage.
Testing Considerations
Existing tests have been ported and expanded. A future improvement could add GC assertions.
Compatibility Considerations
This continues to support SES, just now as a package that can additionally be used elsewhere.
Upgrade Considerations
None known; this is a new package.
Please change the version number to 1.0.0. When this lands, I can do a one-off publish so Agoric integration CI will continue without interruption.
Done. @kriskowal this should be ready to merge, which I'd like to leave in your hands for that initial publish.
@kriskowal this should again be ready to merge, possibly pending re-review from @boneskull.