cachex
Cache Hook
Installation
$ npm install cachex --save
Usage
If you have origin SQL query, it is db.js
:
exports { // mock slow query var rows = await db; return rows;};
Before use cachex
, you must provider an cache storage, it can be redis or memcached or memory.
var inMemory = {}; var store = { return inMemorykey; } { inMemorykey = value; ; };
The storage object must have get/setex yieldable method.
// db_with_cache.jsvar cachex = ;var db = ; // cache result 10s;
Running go:
var db = ;// from dbdb;// from cachedb;// ..10s..pass..// from dbdb;
License
The MIT license