- Source:
Methods
(static) exports.cacheTransaction(callbackOrPromise) → {undefined}
Pass a callback or a promise. All cache changes happening inside the callback or promise will be batched into a single
change object that will be dispatched to handlers after the callback/promise has finished. If this is called while there
is already another transaction in progress, the two transactions will just be batched together.
Parameters:
Name | Type | Description |
---|---|---|
callbackOrPromise |
function | Promise | callback or promise to be executed within the transaction |
- Source:
Returns:
void
- Type
- undefined
(static) exports.clearAllCaches() → {void}
Clear (invalidate) all existing caches.
Will dispatch a single change event with all changes batched together.
- Source:
Returns:
- Type
- void
(static) exports.getCache(valueType) → {LruCache}
Get a LruCache for the given valueType.
If a cache for this type already exists, the existing cache instance will be returned (LruCache is a singleton per value type).
Parameters:
Name | Type | Description |
---|---|---|
valueType |
string | The type of object being cached. |
- Source:
- See:
Returns:
- A lru-cache object.
- Type
- LruCache
(static) exports.registerCacheChangedHandler(changedHandler, valueTypes) → {object}
Register a handler that is called when value(s) get updated/inserted/removed in/to/from a cache.
If the cache has already exceeded its maxSize, there is no way to know if a cache.set (or setAll) is an insert or
an update (because JS does not yet provide weak references), so an insert event can be insert or update.
The returned handle can be used to unregister the handler, or to deactivate/activate it (initial state is active).
Parameters:
Name | Type | Description |
---|---|---|
changedHandler |
function | A function that will be called with an object parameter of the following shape:
{
valueTypes: Set(),
|
valueTypes |
Array | string | An array or a single string specifying the cache value types the handler should be called for (default: null) If null, it will be called for all object types If not null and a bulk (transactional) change has multiple valueTypes of which only some are of interest for the handler, then also the other types will be part of the argument (if at least one other active listener for the other types exist) |
- Source:
Returns:
handlerHandle - An object with methods unregister, activate, deactivate and isRegistered and with fields isActive, valueType and changedHandler
- Type
- object