@fatcherjs/middleware-cache
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

@fatcherjs/middleware-cache

A middleware for caching response result.

codecov install size Size npm package build status

Install

NPM

>$ npm install @fatcherjs/middleware-cache

CDN

<script src="https://cdn.jsdelivr.net/npm/@fatcherjs/middleware-cache/dist/cache.min.js"></script>

Usage

import { cache } from '@fatcherjs/middleware-cache';
import { fatcher } from 'fatcher';

fatcher({
    url: '/bar/foo',
    middlewares: [cache({ ttl: 5 * 60 * 1000 })],
    payload: {
        bar: 'foo',
    },
})
    .then(res => {
        console.log(res);
    })
    .catch(err => {
        console.error(error);
    });

Options

Name Descriptions Type DefaultValue
useCache Whether use cache boolean true
ttl Time to live(ms) number 60 * 1000
validate Validate a request whether needs cache (Context) => boolean context => context.method === 'GET'

License

LICENSE

Readme

Keywords

none

Package Sidebar

Install

npm i @fatcherjs/middleware-cache

Weekly Downloads

0

Version

2.0.0

License

MIT

Unpacked Size

7.93 kB

Total Files

7

Last publish

Collaborators

  • fanhaoyuan