Created
June 5, 2018 11:36
-
-
Save trmcnvn/4659f67265560bf0d2cfe9c62cceded4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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