| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
Many of the performance PRs introduce ad-hoc caching, repeating the same "look up a cached promise, otherwise compute and cache it" logic. This adds a small shared abstraction under src/util/caching so those PRs stop re-writing similar code: - PromiseCache<TKey, TValue>: caches the promise (not just the resolved value) so concurrent callers deduplicate onto a single in-flight computation. It is backed by an injected Map or WeakMap, letting each call site pick process-lifetime caching of a bounded key space (Map) or memory-safe caching keyed on object identity (WeakMap). Entries whose promise rejects are evicted by default so transient failures are retried. - cached(...): a method decorator wrapping a PromiseCache so adoption is a single, minimally invasive annotation. Each instance gets its own cache; the key defaults to the first argument and can be derived via `key`, and `weak` opts into a WeakMap for request-scoped object keys. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The added JSDoc/comments were more verbose than the surrounding util source; condense to the load-bearing facts (promise cached for concurrent dedup, store choice sets entry lifetime, per-instance decorator caches) and drop the type-parameter tags the codebase does not use. No behaviour change. Model: claude-fable-5 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
There was a problem hiding this comment.
Adds reusable promise-based caching utilities for asynchronous computations, including Map/WeakMap support and a per-instance decorator.
Changes:
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file| File | Summary |
|---|---|
| test/unit/util/caching/PromiseCache.test.ts | Promise cache tests; no issues noted. |
| test/unit/util/caching/CachedDecorator.test.ts | Decorator tests; no issues noted. |
| src/util/caching/PromiseCache.ts | Moderate issue: avoid wrapping cached promises in a new async promise (3 votes). |
| src/util/caching/CachedDecorator.ts | Moderate issue: remove the unnecessary async wrapper to preserve promise identity (3 votes). |
| src/index.ts | Public exports; no issues noted. |
src/index.ts:531
export * from './util/caching/CachedDecorator'; export * from './util/caching/PromiseCache';
src/index.ts:531
export * from './util/caching/CachedDecorator'; export * from './util/caching/PromiseCache';
src/util/caching/PromiseCache.ts:45
promise.catch((): void => {
this.store.delete(key);
});
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
📁 Related issues
Addresses #2229.
✍️ Description
Adds two small asynchronous caching utilities:
computations. Its injected Map/WeakMap-compatible store determines entry
lifetime, and rejected promises are evicted by default.
It supports custom key derivation and WeakMap storage for object keys.
The implementation is exported through src/index.ts. This PR introduces the
shared abstraction only; performance measurements belong in changes that
adopt it on an existing hot path.
The utilities are used by these PRs on my fork:
uses PromiseCache to cache compiled EJS and Handlebars templates by path.
uses WeakMap-backed promise caches to deduplicate effective ACL and store
lookups by ResourceIdentifier.
Both PRs are stacked on this work and should be rebased after it lands.
Local verification on current versions/next-major:
covering promise identity, concurrent deduplication, rejection behavior and
eviction races, Map/WeakMap storage, key derivation, and per-instance
isolation
The intended semver level is minor.
✅ PR check list
Before this pull request can be merged, a core maintainer will check whether