lay-away
v1.0.0
Published
A simple cache that's good enough
Readme
Lay Away
A simple cache that's good enough.
Getting Started
Add dependency to project
npm install --save lay-away
Create instance of lay-away
import Cache from 'lay-away'
const cache = Cache()Write data to the cache
cache.set('a', 1)
Read data from the cache
cache.get('a')
Examples
Set entry
import Cache from 'lay-away'
const cache = Cache()
cache.set('a', 1)
console.log(cache.get('a'))
// => 1Set entry with TTL
import Cache from 'lay-away'
import { setTimeout as sleep } from 'node:timers/promises'
const cache = Cache()
cache.set('a', 1, 1000)
console.log(cache.get('a'))
// => 1
await sleep(1000)
console.log(cache.get('a'))
// => undefinedDelete entry
import Cache from 'lay-away'
const cache = Cache()
cache.set('a', 1)
console.log(cache.get('a'))
// => 1
cache.del('a')
console.log(cache.get('a'))
// => undefinedClear all entries
import Cache from 'lay-away'
const cache = Cache()
cache.set('a', 1)
console.log(cache._data.size)
// => 1
cache.clear()
console.log(cache._data.size)
// => 0