cachegoose
cachegoose copied to clipboard
Improve: Support null ttl to disable caching
In case when we have predefined queries with cache invoking and when we need possibility to disable caching it more convenient to change TTL than calling cache method by condition.
For example:
class DB {
constructor(cacheTTL) {
this.cacheTTL = cacheTTL;
}
findAll() {
return Record
.find({})
.cache(this.cacheTTL)
.exec(function(err, records) {
...
});
}
}
new DB(0).findAll(); // Set and get results with cache.
new DB(null).findAll(); // Don't use cache.
Another approach
In general, I would do the following cache TTL value principle:
-
Infinity— Indefinitely caching results -
60— Caching for specified time -
0— Disable caching (cache for 0 seconds)
But that will entail major changes and for this reason I suggest to use null for disable caching.