2.1.0 • Published 20 days ago
fastify-lcache v2.1.0
fastify-lcache
npm i fastify-lcache
Example
// your app
import fastify from 'fastify';
import lcache from 'fastify-lcache';
const app = fastify();
const address = '0.0.0.0';
const port = 4000;
app.register(lcache, {
ttlInMinutes: 10, // set cached data lifetime to 10 minutes
});
app.after(() => {
// add your routes
app.get('/ping', async (req, reply) => {
reply.send('pong');
});
});
app.listen(port, address);
// client wants data from your app
const url = 'http://0.0.0.0:4000/ping';
// first request will return origin data from route '/ping'
// and put result to the cache
axios.get(url);
// the following requests within 10 minutes
// will return cached data on this route
axios.get(url);
API
On fastify instance
interface IStorage {
// Get cached data
get(key: string): any;
// Set data to cache
set(key: string, value: any): void;
// Check if data exists in cache
has(key: string): boolean;
// Clear all data in cache if key not specified
reset(key?: string): void;
// Clear Interval which check data lifetime
destroy(): void;
}
Fastify version compatibility
Fastify | lcache |
---|---|
3-4.9 | 1-1.2 |
^4.10 | 2.x |
2.1.0
20 days ago
2.0.2
27 days ago
2.0.1
2 months ago
2.0.0
5 months ago
1.2.2
5 months ago
1.2.1
5 months ago
1.2.0
6 months ago
1.1.6
7 months ago
1.1.5
7 months ago
1.1.4
7 months ago
1.1.3
9 months ago
1.1.2
9 months ago
1.1.1
1 year ago
1.1.0
2 years ago
1.0.3
2 years ago
1.0.2
2 years ago
1.0.0
2 years ago
0.0.9
2 years ago
0.0.8
2 years ago
0.0.7
2 years ago
0.0.6
2 years ago
0.0.5
2 years ago
0.0.4
2 years ago
0.0.3
2 years ago
0.0.2
2 years ago
0.0.1
2 years ago