pojo-cache-opportunistic-flat-pmb
Shallow-merge a POJO with cached known data if a cache POJO is provided.
API
This module exports one function:
updateCache(cache, key, upd)
If cache
is false
-y, just return upd
.
The idea here is that your library can have an option to use a cache. This module shall help your library transparently use a cache object if one is provided, with minimal performance loss otherwise.
If cache
is truthy, it is assumed to be an object where cache entries
can be stored as its properties.
Missing entries are created on demand, and initialized with an empty object.
If upd
is truthy, its properties are shallow-copied into the cache entry
in-place (replacing the old properties).
Returns the updated cache entry.
Usage
see test/usage.mjs.
Known issues
- Needs more/better tests and docs.
License
ISC