Skip to content

MakerXStudio/node-cache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

NodeJS Cache (node-cache)

A NodeJS package that makes it easy to cache objects and files locally and in AWS

Build Status Issues Semantic Release

Install

npm install @makerx/node-cache

Usage

The primary purpose of this package is to make it easy to cache objects and files.

import { S3 } from '@aws-sdk/client-s3'
import { FileSystemObjectCache, S3ObjectCache } from '@makerx/node-cache'

const cache =
  process.env.CACHE_BUCKET_NAME === 'local'
    ? new FileSystemObjectCache(path.join(__dirname, '../.cache'))
    : new S3ObjectCache(
        new S3({
          region: process.env.AWS_REGION,
        }),
        process.env.CACHE_BUCKET_NAME,
        'optional/cache/prefix',
      )

for (let i =0; i < 10; i++>) {
  const value = await cache.getAndCache('test', async (existing: {test: number} | undefined) => {
    await new Promise(resolve => setTimeout(resolve, 100))
    const e = existing ?? {test: 1}
    e.test++
    return e
  }, {
    staleAfterSeconds: 1
  })
  console.log(value)
  await new Promise(resolve => setTimeout(resolve, 500))
}

await cache.put('test', {test: 100})

About

NodeJS package that makes it easy to cache objects and files locally and in AWS

Topics

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages