@neumatter/object-cache
v1.0.0
Published
Module for creating ObjectCaches that can be garbage collected.
Downloads
22
Maintainers
Readme
ObjectCache
Module for creating ObjectCaches that can be garbage collected. The ObjectCache will delete the least-recently-used entry to make room for new entries.
Table of Contents
Install
npm i @neumatter/object-cacheUsage
import ObjectCache from '@neumatter/object-cache'
class CustomObject {
constructor () {}
get () {
const objectCache = ObjectCache.from(this, { maxSize })
let value = objectCache.get('key')
if (value === undefined) {
value = someExpensiveOp()
objectCache.set('key', value)
}
return value
}
}