caching-middleware
caching middleware for expressesk backends
Install
npm install caching-middleware --save
See migration guide due to breaking changes from v1 to v2
Usage
This middleware will try to retrieve data via a defined primary
method.
If no entry was found, it will try to use a fallback
method (here you can query against your database). If the fallback
method returns a value, the update
method will be executed, where you can ideally rehydrate your cache. On the next request the data would be retrieved the from the primary method.
const cache = ; //const db = ... //const memCache = ... const app = ; const withUser = ; app;
Usecase
You can for example retrieve further information about the requester (user), without targeting the database on each request all over again.
Tests
npm install
npm test
Example App
cd example
npm install
./run.sh or npm start