punycache
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

punycache 🦴

Node.js CI Mutation Testing no dependencies JavaScript Style Guide Package Quality Known Vulnerabilities punycache punycache install size MIT License

A minimalist cache implementation.

Usage

const cache = require('punycache')()

cache.set('key', 'Hello World !')
console.log(cache.get('key')) // Hello World !
console.log(cache.keys()) // [ 'key' ]
console.del('key')
console.log(cache.get('key')) // undefined

Options

const cache = require('punycache')({
  ttl: 200,
  max: 100,
  policy: 'lfu'
})
  • ttl : (default: Number.POSITIVE_INFINITY) Time to live in the cache, expressed in milliseconds
  • max : (default: Number.POSITIVE_INFINITY) Maximum number of keys to be stored in the cache (see policy for cache replacement policies)
  • policy : Cache replacement policy, supported values are
    • 'lru' (default) Least Recently Used (each get / set updates used timestamp)
    • 'lfu' Least Frequently Used (each get / set increments usage frequency)

Implementation notes :

  • keys are expected to be strings but no validation is done
  • Values are stored and returned as-is
  • Keys are removed from the cache ad-hoc (no timeout is being used)

Readme

Keywords

Package Sidebar

Install

npm i punycache

Weekly Downloads

26

Version

1.0.0

License

MIT

Unpacked Size

6.71 kB

Total Files

5

Last publish

Collaborators

  • arnaud.buchholz