pojo-cache-opportunistic-flat-pmb

0.1.1 • Public • Published

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

Package Sidebar

Install

npm i pojo-cache-opportunistic-flat-pmb

Weekly Downloads

1

Version

0.1.1

License

ISC

Unpacked Size

6.19 kB

Total Files

6

Last publish

Collaborators

  • mk-pmb