I’ve been looking at doing some caching in my project, and I seem to have hit a roadblock…
How do I open existing cache instances?
Right now I’m doing it as such, within the part using the cached data:
var cache = libs.cache.newCache({
size: 100,
expire: 3600
});
var a = cache.get('mykey', function() {
return generatorfunction()});
Checking the size of the cache, this will successfully save the data from the generatorfunction.
The code above will trigger on each GET request for this specific part. But this seems to be only creating a new empty cache instance on each request.
Do I need to structure it differently?
Looking at the cache docs, I cant seem to find an answer to my question.
Code outside the request handlers will be initiated only once, while code inside the handlers will be triggered each time that specific request method is sent. So basically you created a new temporary cache and filled it for each request. We could definitely improve the docs on that part.