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

Add cache disabling for datasets #254

Merged
merged 5 commits into from
Oct 12, 2018

Conversation

cdtinney
Copy link
Contributor

@cdtinney cdtinney commented Oct 6, 2018

Summary

Adds the ability to disable cache retrieval of subsequent identical queries via a boolean flag in dataset config called disableCache.

Use case:

  • Query suggestions may differ between queries if the data on the server changes, and it is critical to display up-to-date suggestions

Related issues:

Additional notes:

  • Fixed typo in test case name

@coveralls
Copy link

coveralls commented Oct 6, 2018

Coverage Status

Coverage increased (+0.01%) to 88.854% when pulling a67320b on cdtinney:dataset-disable-cache into d343bee on algolia:master.

@Haroenv
Copy link
Contributor

Haroenv commented Oct 8, 2018

This one definitely sounds like the more reasonable of both PRs, @samouss, what do you think?

@@ -37,6 +37,8 @@ function Dataset(o) {

this.debounce = o.debounce;

this.disableCache = !!o.disableCache;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would go for enableCache (or something similar) with a default value to true rather than disableCache. Positive condition are a bit easier to reason about.

@@ -235,6 +237,10 @@ _.mixin(Dataset.prototype, EventEmitter, {
},

shouldFetchFromCache: function shouldFetchFromCache(query) {
if (this.disableCache) {
return false;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once we have inverted the condition we can inline the condition.

@samouss
Copy link
Contributor

samouss commented Oct 11, 2018

@Haroenv The tests are failing because of the Netlify ENV variable not available on contributors PR.

Copy link
Contributor

@samouss samouss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes! For the option name we can go for cache rather than enableCache no? WDYT? cc @Haroenv

@Haroenv
Copy link
Contributor

Haroenv commented Oct 11, 2018

Agreed with @samouss, cache: true seems like a good name!

@Haroenv Haroenv merged commit 0e65fee into algolia:master Oct 12, 2018
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.

4 participants