1.0.0 • Published 10 months ago

@neumatter/object-cache v1.0.0

Weekly downloads
-
License
-
Repository
github
Last release
10 months ago

ObjectCache

plot plot JavaScript Style Guide

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-cache

Usage

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
  }
}