>$ npm install @fatcherjs/middleware-cache<script src="https://cdn.jsdelivr.net/npm/fatcher/dist/fatcher.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@fatcherjs/middleware-cache/dist/index.min.js"></script>
<script>
Fatcher.fatcher('url', {
middlewares: [FatcherMiddlewareCache.cache],
ttl: 60 * 1000, // 60s
}).then(async response => {
const text = await response.text();
Fatcher.fatcher('url', {
middlewares: [FatcherMiddlewareCache.cache],
}).then(async response2 => {
const text2 = await response2.text();
console.log(text === text2); // true
});
});
</script>import { fatcher } from 'fatcher';
import { cache } from '@fatcherjs/middleware-cache';
fatcher('https://foo.bar', {
middlewares: [cache],
});import { fatcher } from 'fatcher';
import { cache } from '@fatcherjs/middleware-cache';
fatcher('https://foo.bar', {
ttl: 5 * 1000,
middlewares: [cache],
});import { fatcher } from 'fatcher';
import { cache } from '@fatcherjs/middleware-cache';
fatcher('https://foo.bar', {
ttl: 5 * 1000,
middlewares: [cache],
});
fatcher('https://foo.bar', {
ttl: 5 * 1000,
flush: true, // ignore cache and refresh cache with ttl > 0
middlewares: [cache],
});import { fatcher } from 'fatcher';
import { cache, clearCache } from '@fatcherjs/middleware-cache';
fatcher('https://foo.bar', {
ttl: 5 * 1000,
middlewares: [cache],
});
clearCache('https://foo.bar'); // clear single cache
clearCache(); // clear all cache