Skip to content

lsdsoftware/simple-cache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

simple-cache

Memory and disk cache implementations with simple TTL.

For use with multilayer-async-cache-builder

Install

npm i @lsdsoftware/simple-cache

Example

Create a 2-layer cache:

Layer Type Info
1 Memory ttl: 60 seconds, cleanupInterval: 60 seconds
2 Disk ttl: 1 hour, cleanupInterval: 15 minutes
import { Fetch } from "multilayer-async-cache-builder"
import { MemCache, DiskCache } from "@lsdsoftware/simple-cache"

//define your fetch function
const fetchItem: (id: string) => Promise<{data: Buffer, metadata: any}>

const getItem = new Fetch(fetchItem)
  .cache(new DiskCache("path/to/cache/folder", ms("1 hour"), ms("15 minutes")))
  .cache(new MemCache(ms("1 minute"), ms("1 minute")))
  .dedupe()

//use
getItem("item-id").then(useItem);

About

Memory and disk cache implementations with simple TTL

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published