https://github.com/makerxstudio/node-cache
NodeJS package that makes it easy to cache objects and files locally and in AWS
https://github.com/makerxstudio/node-cache
aws cache npm package s3 typescript
Last synced: 5 months ago
JSON representation
NodeJS package that makes it easy to cache objects and files locally and in AWS
- Host: GitHub
- URL: https://github.com/makerxstudio/node-cache
- Owner: MakerXStudio
- License: mit
- Created: 2024-01-05T06:07:17.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-06-21T03:55:50.000Z (about 2 years ago)
- Last Synced: 2025-09-28T21:48:12.069Z (9 months ago)
- Topics: aws, cache, npm, package, s3, typescript
- Language: TypeScript
- Homepage:
- Size: 557 KB
- Stars: 1
- Watchers: 10
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# NodeJS Cache (node-cache)
> A NodeJS package that makes it easy to cache objects and files locally and in AWS
[![Build Status][build-img]][build-url]
[![Issues][issues-img]][issues-url]
[![Semantic Release][semantic-release-img]][semantic-release-url]
## Install
```bash
npm install @makerx/node-cache
```
## Usage
The primary purpose of this package is to make it easy to cache objects and files.
```typescript
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})
```
---
[build-img]: https://github.com/MakerXStudio/node-cache/actions/workflows/release.yaml/badge.svg
[build-url]: https://github.com/MakerXStudio/node-cache/actions/workflows/release.yaml
[issues-img]: https://img.shields.io/github/issues/MakerXStudio/node-cache
[issues-url]: https://github.com/MakerXStudio/node-cache/issues
[semantic-release-img]: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg
[semantic-release-url]: https://github.com/semantic-release/semantic-release