forge/cache
Source: cache.js:7
Storage primitives — the Cache class and its helpers.
Static Methods
createCache(entries, options) -> Cache
Create a Cache pre-populated from an object of key/value pairs.
This is a global function (no @memberof), so it appears on the aggregated Globals page rather than owning its own page.
Parameters
entries(Object.<string, *>) — Initial entries to seed the cache with.options(CacheOptions, optional) — Options forwarded to the Cache constructor.
Returns
Cache— A new, seeded cache.
Example
const cache = createCache({ a: 1, b: 2 }, { maxSize: 10 });
cache.get('b'); // => 2- Since: 1.0.0
Enums
Priority
Relative priority for cached writes — a numeric enum rendered as a member table on the Globals page.
Type
number
Other
CacheOptions
Options accepted by the Cache constructor.
Properties
maxSize(number, optional, default: 100) — Maximum number of entries to keep before the least-recently-used entry is evicted.ttl(number, optional, default: 0) — Time-to-live for an entry, in milliseconds.0disables expiry.freeze(boolean, optional, default: false) — Freeze values on insert so callers can't mutate cached objects.
Type
Object
Cache
Implements: Store, Serializable
A tiny in-memory, least-recently-used (LRU) cache.
This class is the showcase's centerpiece: its members exercise nearly every member-level tag the theme renders — parameters, returns, examples, events, deprecation, modifiers, and cross-references.
A
Cacheis not thread-safe across workers. Wrap shared access in a Queue if you need ordered writes.
Eviction follows a strict recency order:
| Operation | Effect on recency |
|---|---|
set(k, v) | marks k most-recently-used |
get(k) | marks k most-recently-used |
has(k) | no change |
Parameters
options(CacheOptions, optional, default: "{}") — Configuration for the cache.options.maxSize(number, optional, default: 100) — Max entries before eviction.options.ttl(number, optional, default: 0) — Per-entry time-to-live in ms.
Throws
RangeError— IfmaxSizeis not a positive integer.
Example
Basic usage
const cache = new Cache({ maxSize: 2 });
cache.set('a', 1).set('b', 2);
cache.get('a'); // => 1, and 'a' is now most-recently-used- Since: 1.0.0
- Version: 1.2.0
- Author: The clean-jsdoc-theme team
- See:
- CacheOptions
- createCache for a one-shot factory