Skip to content

Conversation

@tenorok
Copy link
Contributor

@tenorok tenorok commented Mar 13, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant