Skip to content
This repository has been archived by the owner on Jun 12, 2022. It is now read-only.

Commit

Permalink
feat(memoization): only slurp stuff into memory if opts.memoize is no…
Browse files Browse the repository at this point in the history
…t false
  • Loading branch information
zkat committed Apr 28, 2017
1 parent 8a9ed4c commit 0744adc
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions cache.js
Expand Up @@ -66,7 +66,7 @@ module.exports = class Cache {
cb(null, chunk, enc)
} else {
disturbed = true
if (info.size > MAX_MEM_SIZE) {
if (opts.memoize !== false && info.size > MAX_MEM_SIZE) {
pipe(
cacache.get.stream.byDigest(cachePath, info.integrity),
body,
Expand All @@ -75,7 +75,7 @@ module.exports = class Cache {
} else {
// cacache is much faster at bulk reads
cacache.get.byDigest(cachePath, info.integrity, {
memoize: true
memoize: opts.memoize !== false
}).then(data => {
body.write(data, () => {
body.end()
Expand Down Expand Up @@ -106,7 +106,7 @@ module.exports = class Cache {
// Takes both a request and its response and adds it to the given cache.
put (req, response, opts) {
const size = response.headers.get('content-length')
const fitInMemory = !!size && size < MAX_MEM_SIZE
const fitInMemory = !!size && opts.memoize !== false && size < MAX_MEM_SIZE
const ckey = cacheKey(req)
const cacheOpts = {
algorithms: opts.algorithms,
Expand Down

0 comments on commit 0744adc

Please sign in to comment.