Skip to content

mk-pmb/pojo-cache-opportunistic-flat-pmb-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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[, create]])

If cache is false-y, just return upd. Except if create is also given, then a temporary cache entry (that will not be saved into any cache) will be created as described below.

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. If create is truthy, it's expected to be a function that returns the initial value for a new cache entry. If create is false-y, the entry will be 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.

Difference to getoraddkey-simple

  • This module is even simpler: Less features, less code.
  • This module merges the new data with the existing cache entry.

Known issues

  • Needs more/better tests and docs.

 

License

ISC

About

Shallow-merge a POJO with cached known data if a cache POJO is provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published