Sha256: 753a9ff8317e063b6c4d13cfb6708f4ed051897f13991a350b5c3769006708d7

Contents?: true

Size: 1.52 KB

Versions: 44

Compression:

Stored size: 1.52 KB

Contents

'use strict'

const LRU = require('lru-cache')

const MAX_SIZE = 50 * 1024 * 1024 // 50MB
const MAX_AGE = 3 * 60 * 1000

let MEMOIZED = new LRU({
  max: MAX_SIZE,
  maxAge: MAX_AGE,
  length: (entry, key) => {
    if (key.startsWith('key:')) {
      return entry.data.length
    } else if (key.startsWith('digest:')) {
      return entry.length
    }
  }
})

module.exports.clearMemoized = clearMemoized
function clearMemoized () {
  const old = {}
  MEMOIZED.forEach((v, k) => {
    old[k] = v
  })
  MEMOIZED.reset()
  return old
}

module.exports.put = put
function put (cache, entry, data, opts) {
  pickMem(opts).set(`key:${cache}:${entry.key}`, { entry, data })
  putDigest(cache, entry.integrity, data, opts)
}

module.exports.put.byDigest = putDigest
function putDigest (cache, integrity, data, opts) {
  pickMem(opts).set(`digest:${cache}:${integrity}`, data)
}

module.exports.get = get
function get (cache, key, opts) {
  return pickMem(opts).get(`key:${cache}:${key}`)
}

module.exports.get.byDigest = getDigest
function getDigest (cache, integrity, opts) {
  return pickMem(opts).get(`digest:${cache}:${integrity}`)
}

class ObjProxy {
  constructor (obj) {
    this.obj = obj
  }
  get (key) { return this.obj[key] }
  set (key, val) { this.obj[key] = val }
}

function pickMem (opts) {
  if (!opts || !opts.memoize) {
    return MEMOIZED
  } else if (opts.memoize.get && opts.memoize.set) {
    return opts.memoize
  } else if (typeof opts.memoize === 'object') {
    return new ObjProxy(opts.memoize)
  } else {
    return MEMOIZED
  }
}

Version data entries

44 entries across 34 versions & 12 rubygems

Version Path
optimacms-0.1.61 spec/dummy/node_modules/terser-webpack-plugin/node_modules/cacache/lib/memoization.js
disco_app-0.18.0 test/dummy/node_modules/cacache/lib/memoization.js
disco_app-0.18.0 test/dummy/node_modules/terser-webpack-plugin/node_modules/cacache/lib/memoization.js
disco_app-0.18.2 test/dummy/node_modules/cacache/lib/memoization.js
disco_app-0.18.2 test/dummy/node_modules/terser-webpack-plugin/node_modules/cacache/lib/memoization.js
disco_app-0.16.1 test/dummy/node_modules/terser-webpack-plugin/node_modules/cacache/lib/memoization.js
disco_app-0.15.2 test/dummy/node_modules/terser-webpack-plugin/node_modules/cacache/lib/memoization.js
disco_app-0.18.4 test/dummy/node_modules/terser-webpack-plugin/node_modules/cacache/lib/memoization.js
disco_app-0.18.1 test/dummy/node_modules/terser-webpack-plugin/node_modules/cacache/lib/memoization.js
disco_app-0.12.7.pre.puma.pre.3 test/dummy/node_modules/terser-webpack-plugin/node_modules/cacache/lib/memoization.js
disco_app-0.14.0 test/dummy/node_modules/terser-webpack-plugin/node_modules/cacache/lib/memoization.js
disco_app-0.13.6.pre.puma.pre.3 test/dummy/node_modules/terser-webpack-plugin/node_modules/cacache/lib/memoization.js
tang-0.2.1 spec/tang_app/node_modules/webpack/node_modules/cacache/lib/memoization.js
groonga-client-model-6.0.0 test/apps/rails6.1.3/node_modules/webpack/node_modules/cacache/lib/memoization.js
groonga-client-model-6.0.0 test/apps/rails6.0.3.5/node_modules/webpack/node_modules/cacache/lib/memoization.js
ruby2js-4.0.4 lib/tasks/testrails/node_modules/webpack/node_modules/cacache/lib/memoization.js
ruby2js-4.0.3 lib/tasks/testrails/node_modules/webpack/node_modules/cacache/lib/memoization.js
tang-0.2.0 spec/tang_app/node_modules/webpack/node_modules/cacache/lib/memoization.js
tang-0.1.0 spec/tang_app/node_modules/webpack/node_modules/cacache/lib/memoization.js
tang-0.0.9 spec/tang_app/node_modules/webpack/node_modules/cacache/lib/memoization.js