Skip to content

Latest commit

 

History

History
42 lines (33 loc) · 1.18 KB

README.md

File metadata and controls

42 lines (33 loc) · 1.18 KB

single-value-cache

npm version Coverage Status

Simple, TTL-based Node.js cache for single values. Returns undefined if user attempts to retrieve expired value.

Usage

Setting new value

import { SingleValueCache } from 'single-value-cache'

const cache = new SingleValueCache(500) // TTL in msecs
cache.set('token')
const token = cache.get()
expect(token).toEqual('token')

Clearing cache

import { SingleValueCache } from 'single-value-cache'

const cache = new SingleValueCache(500) // TTL in msecs
cache.set('token')
cache.clear()
const token = cache.get()
expect(token).toBeUndefined()

Updating value

import { SingleValueCache } from 'single-value-cache'

const cache = new SingleValueCache(500) // TTL in msecs
cache.set('token')
cache.set('token2')
const token = cache.get()
expect(token).toEqual('token2')