Lay Away
A simple cache that's good enough.
Getting Started
Examples
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'))
Set 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'))
await sleep(1000)
console.log(cache.get('a'))
Delete entry
import Cache from 'lay-away'
const cache = Cache()
cache.set('a', 1)
console.log(cache.get('a'))
cache.del('a')
console.log(cache.get('a'))
Clear all entries
import Cache from 'lay-away'
const cache = Cache()
cache.set('a', 1)
console.log(cache._data.size)
cache.clear()
console.log(cache._data.size)