1.0.0 • Published 7 years ago
l2-cache v1.0.0
L1L2Cache
this module is a helper to aid a consume two layers cache
dependencies
- redis
usage
/* config to point a instance of redis */
const config = {
url: "redis://localhost"
}
/* when cache value is not found, this callback was update*/
const updateCallback = function*(l1, l2) {
// ... update logic, send to a queue or update here
}
const l2Cache = new L2Cache(config, updateCallback)
/* first time cache value is not found*/
const ad = l2Cache.get("http://api.example.com/ads/abc")
/* null */
/* in second time, value already was updated */
const ad = l2Cache.get("http://api.example.com/ads/abc")
/* {
id: "abc",
cpc: 0.4
} */
1.0.0
7 years ago