Express middleware to cache API routes
const cacheMiddleware = require('node-cache-middleware');
app.get(
'/slow_endpoint',
cacheMiddleware({
durationMilliseconds: 30 * 1000,
}),
(req, res, next) => "..."
);
This comes with a in-memory cache using the Node memory-cache
package.
It does support writing your own adapter for memcached/redis or whatever else
floats your boat.
Based on kwhitley/apicache, and addisonj/node-cacher, but with some changes to better handle the thundering herd problem.