infinicache

0.1.0 • Public • Published

infinicache

A cache for Node.js that can use all available system memory without crashing. It's based on WeakRef and FinalizationRegistry.

Install

npm i infinicache

Usage

import Cache from 'infinicache'
import { promisify } from 'util'

const immediate = promisify(setImmediate)

const cache = new Cache()

// Create a scope so that obj goes
// out of scope
{
  const obj = { foo: 'bar' }
  cache.set('hello', obj)
  console.log(cache.get('hello'))
}

await immediate()

// We need to allocate a bazillion amount of objects
// to trigger a GC
const data = []
for (let i = 0; i < 1000000; i++) {
  data.push({ i })
}

console.log(cache.get('hello'))

Note that this Cache is slower than most LRU caches. If you are looking for an LRU cache, use mnemonist LRUCache.

License

MIT

Dependencies (0)

    Dev Dependencies (3)

    Package Sidebar

    Install

    npm i infinicache

    Weekly Downloads

    1

    Version

    0.1.0

    License

    MIT

    Unpacked Size

    5.03 kB

    Total Files

    5

    Last publish

    Collaborators

    • matteo.collina