@lsdsoftware/simple-cache
TypeScript icon, indicating that this package has built-in type declarations

3.2.0 • Public • Published

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:

Layer Type Info
1 Memory ttl: 60 seconds, cleanupInterval: 60 seconds
2 Disk ttl: 1 hour, cleanupInterval: 15 minutes
3 S3 ttl: (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);

Readme

Keywords

none

Package Sidebar

Install

npm i @lsdsoftware/simple-cache

Weekly Downloads

4

Version

3.2.0

License

MIT

Unpacked Size

31.9 kB

Total Files

19

Last publish

Collaborators

  • ken107