3.2.0 • Published 7 months ago

@lsdsoftware/simple-cache v3.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

simple-cache

Memory, disk, and S3 cache implementations with simple TTL. Cache keys can be any object but must have a valid toString().

For use with multilayer-async-cache-builder

Install

npm i ssh://github.com/ken107/simple-cache

Example

Create a 3-layer cache:

LayerTypeInfo
1Memoryttl: 60 seconds, cleanupInterval: 60 seconds
2Diskttl: 1 hour, cleanupInterval: 15 minutes
3S3ttl: (use bucket lifecycle rules)
import { Fetch } from "multilayer-async-cache-builder"
import { MemCache, DiskCache, S3Cache } from "simple-cache"

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

const getItem = new Fetch(fetchItem)
  .cache(new S3Cache(s3, "my-bucket"))
  .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);
3.2.0

7 months ago

3.1.1

8 months ago

3.1.0

8 months ago

3.0.4

2 years ago

3.0.3

2 years ago

3.0.2

2 years ago

3.0.1

2 years ago

3.0.5

2 years ago

3.0.0

2 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.2.0

3 years ago

1.1.0

3 years ago

1.0.0

4 years ago