![]() |
Infohub JS API
|
@fileoverview Minimal in-memory cache with TTL and tagging.
Small utility used by services to cache HTTP results in case of success. A generic, reusable in-memory cache with optional TTL, metadata, and predicate-based invalidation. Works for any data shape.
Exposed globally as window.CacheStore
Generic in-memory cache with TTL and tag-based invalidation.
Typical usage:
Public Member Functions | |
| clear () | |
| constructor (defaultTTLms=null) | |
| delete (key) | |
| deleteWhere (predicate) | |
| get (key) | |
| getEntry (key) | |
| async | getOrCompute (key, compute, options={}) |
| has (key) | |
| markNeedUpdate (key) | |
| markNeedUpdateWhere (predicate) | |
| set (key, value, options={}) | |
| clear | ( | ) |
Clear all entries.
| constructor | ( | defaultTTLms = null | ) |
| {number|null} | defaultTTLms default TTL in milliseconds for entries set without an explicit ttl |
| delete | ( | key | ) |
Delete a key.
| {string} | key |
| deleteWhere | ( | predicate | ) |
Delete entries where the predicate matches.
| {function(string,{ | value: *, needUpdate: boolean, tags: (Object<string, *>|undefined) }): boolean} predicate |
| get | ( | key | ) |
Get only the value for a key (undefined if missing or expired).
| {string} | key |
| getEntry | ( | key | ) |
Get the full entry including metadata (undefined if missing or expired).
| {string} | key |
| async getOrCompute | ( | key, | |
| compute, | |||
| options = {} ) |
Get or compute and store a value under a key.
@template T
| {string} | key |
| {function() | (T|Promise<T>)} compute |
| {Object} | [options] |
| {(number|null)} | [options.ttlMs] |
| {Object<string,*>} | [options.tags] |
| has | ( | key | ) |
Returns whether a key exists and is not expired.
| {string} | key |
| markNeedUpdate | ( | key | ) |
Mark one key as needing update (stale).
| {string} | key |
| markNeedUpdateWhere | ( | predicate | ) |
Mark entries as needing update where the predicate matches.
| {function(string,{ | value: *, needUpdate: boolean, tags: (Object<string, *>|undefined) }): boolean} predicate |
| set | ( | key, | |
| value, | |||
| options = {} ) |
Set a cache value.
| {string} | key |
| {*} | value |
| {Object} | [options] |
| {(number|null)} | [options.ttlMs] |
| {boolean} | [options.needUpdate] |
| {Object<string,*>} | [options.tags] |