Skip to content
This repository has been archived by the owner on Jul 3, 2019. It is now read-only.

Commit

Permalink
feat(memo): added memoization lib
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat committed Mar 2, 2017
1 parent b639746 commit da07b92
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions lib/memoization.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use strict'

let MEMOIZED = {}

module.exports.clearMemoized = clearMemoized
function clearMemoized () {
var old = MEMOIZED
MEMOIZED = {}
return old
}

module.exports.put = put
function put (cache, entry, data) {
MEMOIZED[`key:${cache}:${entry.key}`] = { entry, data }
putDigest(cache, entry.digest, entry.hashAlgorithm, data)
}

module.exports.put.byDigest = putDigest
function putDigest (cache, digest, algo, data) {
MEMOIZED[`digest:${cache}:${algo}:${digest}`] = data
}

module.exports.get = get
function get (cache, key) {
return MEMOIZED[`key:${cache}:${key}`]
}

module.exports.get.byDigest = getDigest
function getDigest (cache, digest, algo) {
return MEMOIZED[`digest:${cache}:${algo}:${digest}`]
}

0 comments on commit da07b92

Please sign in to comment.