You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
460 B
24 lines
460 B
5 years ago
|
'use strict'
|
||
|
|
||
|
var p = require('primitive-pool')
|
||
|
var WeakMap = require('weak-map')
|
||
|
|
||
|
// cache of data without clipping, depending on source
|
||
|
var cache = new WeakMap()
|
||
|
|
||
|
module.exports = {
|
||
|
get: function (key) {
|
||
|
return cache.get(p(key))
|
||
|
},
|
||
|
set: function (key, value) {
|
||
|
if (!Array.isArray(key)) key = [key]
|
||
|
|
||
|
key.forEach(function (key) {
|
||
|
if (!key) return
|
||
|
if (!cache.get(p(key))) cache.set(p(key), value)
|
||
|
})
|
||
|
|
||
|
return value
|
||
|
}
|
||
|
}
|