https://github.com/hkk12369/file-cache
File Based Cache for Node.js
https://github.com/hkk12369/file-cache
Last synced: 2 months ago
JSON representation
File Based Cache for Node.js
- Host: GitHub
- URL: https://github.com/hkk12369/file-cache
- Owner: hkk12369
- License: mit
- Created: 2022-07-08T13:46:08.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-06-18T15:46:21.000Z (12 months ago)
- Last Synced: 2025-04-01T11:44:00.086Z (3 months ago)
- Language: JavaScript
- Size: 38.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## file-cache
File Based Cache for Node.js## Install
```sh
npm install @hkk12369/file-cache
# OR
yarn add @hkk12369/file-cache
```## Usage
```js
const {FileCache} = require('@hkk12369/file-cache');// set cache directory
FileCache.setCacheDir('./cache');const cache = new FileCache('api');
// set any key
await cache.set('key', 'value', {ttl: '1d'});
// get key
await cache.get('key');
// delete key
await cache.del('key');
// get key or set if not exists
await cache.getOrSet('key', async () => {
return 'value';
}, {ttl: '1d'});
// get stale key and set in background if stale
await cache.getOrSet('key', async () => {
return 'value';
}, {ttl: '30d', staleTTL: '1d'});
```