Skip to content

Instantly share code, notes, and snippets.

@lorensr
Created April 2, 2020 09:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lorensr/8bccc82d23d6e49ec63534e6f00cb41e to your computer and use it in GitHub Desktop.
Save lorensr/8bccc82d23d6e49ec63534e6f00cb41e to your computer and use it in GitHub Desktop.
async get(id, { ttlInSeconds } = {}) {
const cacheDoc = await cache.get(this.cacheKey(id))
if (cacheDoc) {
return JSON.parse(cacheDoc)
}
const doc = await this.loader.load(id)
if (ttlInSeconds) {
cache.set(this.cacheKey(id), JSON.stringify(doc), { ttl: ttlInSeconds })
}
return doc
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment