Skip to content

Instantly share code, notes, and snippets.

@trmcnvn
Created June 5, 2018 11:36
Show Gist options
  • Save trmcnvn/4659f67265560bf0d2cfe9c62cceded4 to your computer and use it in GitHub Desktop.
Save trmcnvn/4659f67265560bf0d2cfe9c62cceded4 to your computer and use it in GitHub Desktop.
action(query) {
const options = Object.assign({ cache: true }, query.options);
let key = Object.assign({}, query.expression, options);
key = JSON.stringify(sortObject(key));
const value = QUERY_CACHE[key];
if (value) {
if ((new Date()) > value) {
delete QUERY_CACHE[key];
} else {
return this.source.cache.query(query);
}
}
// create a cache entry in the weakmap
if (options.cache) {
const date = new Date();
date.setTime(date.getTime() + (CACHE_TIME_HOUR * 60 * 60 * 1000));
QUERY_CACHE[key] = date;
}
// hit the target store
return this.target.pull(query);
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment