Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve: Support null ttl to disable caching #69

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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