@vates/simple-cache

1.2.0 • Public • Published

@vates/simple-cache

A simple caching module

Install

npm install @vates/simple-cache

Usage

Set a key

set(key, data, ttl?)

import Cache from '@vates/simple-cache';

const emailsCache = new Cache()
emailsCache.set("customer123", "customer123@mail.com")

Get a key

get(key)

cache.get("customer123")
//=> { data: 'customer123@mail.com', date: 1715870399907, expireAt: 1715870419907 }

Cache function

Caches the return of a function

withCache(function, args = [], options = {expireAt, key})

cache.withCache(fetch, [url, { method: "POST" }], { expireAt: 5000 });
//=> data

IsExpired

isExpired(key)

cache.isExpired("customer123")
//=> true/false

Clear cache

clearCache(key?)

cache.clearCache("customer123")
cache.clearCache()

Readme

Keywords

none

Package Sidebar

Install

npm i @vates/simple-cache

Weekly Downloads

7

Version

1.2.0

License

MIT

Unpacked Size

4.04 kB

Total Files

3

Last publish

Collaborators

  • mlssfrncjrg
  • b-nollet
  • arnogues
  • florent.beauchamp
  • mathieura
  • enishowk
  • tgoettelmann
  • julien-f
  • marsaud
  • olivierlambert
  • pdonias