cachette v2.0.2
cachette
Resilient cache library supporting concurrent requests through local cache or Redis.
This repo is a work-in-progress and is not ready for general use.
Installation
npm install --save cachette
Basic usage
const { WriteThroughCache } = require('cachette');
// First, initialize the redis connection.
const cache = new WriteThroughCache(process.env.REDIS_URL);
async function fetchUrl(url) {
console.log('fetching', url);
const response = await fetch(url);
console.log('fetched', url);
}
async function fetchUrlCached(url) {
const fetchFunction = fetchUrl.bind(undefined, url);
return cache.getOrFetchValue(url, 600, fetchFunction);
}
fetchUrlCached('https://unito.io').then(() => console.log('first call returned'));
// First call fetches the resource, the other calls use the cached value.
fetchUrlCached('https://unito.io').then(() => console.log('second call returned'));
fetchUrlCached('https://unito.io').then(() => console.log('third call returned'));
License
MIT
1 month ago
2 months ago
3 months ago
3 months ago
3 months ago
3 months ago
4 months ago
5 months ago
7 months ago
8 months ago
9 months ago
10 months ago
5 months ago
6 months ago
6 months ago
6 months ago
11 months ago
12 months ago
1 year ago
1 year ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago