feat(cache): add unified Cache#7082
Open
tomas-zijdemans wants to merge 11 commits intodenoland:mainfrom
Open
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #7082 +/- ##
==========================================
+ Coverage 94.41% 94.46% +0.05%
==========================================
Files 630 630
Lines 50490 50876 +386
Branches 8949 9041 +92
==========================================
+ Hits 47669 48060 +391
+ Misses 2249 2243 -6
- Partials 572 573 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
NOTE: Builds on this PR
This PR replaces
LruCacheandTtlCachewith a singleCache<K, V>that unifies LRU eviction, TTL expiration, stale-while-revalidate, and load-through (getOrLoad).The existing caches extend
Map, so inherited methods bypass LRU/TTL logic entirely. Both subclassMap, making it structurally impossible to compose LRU with TTL.Cache<K, V>uses composition over inheritance: it owns aMapfor storage and delegates toIndexedHeapfor deadline-ordered expiration. Mode is determined by options, not class choice, and a discriminated union onCacheOptionsmakes illegal combinations compile-time errors.Beyond fixing the structural issues, this introduces capabilities that didn't exist before:
getOrLoad(key, loader)with automatic in-flight deduplicationsetTimeoutsSymbol.disposeSince
@std/cacheis still experimental (0.2.2), this is the right time to make a clean break before stabilization locks things in.