Clyng57 / object-cache

Module for creating ObjectCaches that can be garbage collected.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

About

Module for creating ObjectCaches that can be garbage collected.

License:MIT License


Languages

Language:JavaScript 100.0%