cachegoose icon indicating copy to clipboard operation
cachegoose copied to clipboard

Improve: Support null ttl to disable caching

Open tenorok opened this issue 4 years ago • 0 comments

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.

tenorok avatar Mar 13 '21 20:03 tenorok