apicache
apicache copied to clipboard
is dynamic duration possible?
Hi,
In some cases, it may be necessary to dynamically give the duration parameter.
something like this.
cache((req) => {
if (req.mycondition) {
return '1 minute';
}
return '1 hour';
});
i don't see why you couldn't use a function's output when setting the cache time
something like
const dynamicTime = () => { // ...criteria }
app.use(cache( dynamicTime() ))
// or with redis
app.get('/will-be-cached', cacheWithRedis( dynamicTime() ), (req, res) => {
res.json({ success: true })
})
Actually, what I want to say is:
I'm using a whole domain as a proxy, but I want to give different cache times for some paths.
const myProxy = createProxyMiddleware({
target: 'www.my-proxy-url.com'
});
app.use(`/`, apicache.middleware('1 minute'), myProxy);
in this case i want to cache like this.
www.my-proxy-url.com/api/path1 ( 1 minute ) www.my-proxy-url.com/api/path2 ( 1 hour )