Code Monkey home page Code Monkey logo

request-cacher's Introduction

Request Cacher

Cache network request data to avoid repeated requests and improve response time.

Install

npm install request-cacher -S

Usage

import {requestCache} from 'request-cacher'
// import axios from 'axios'
async function getData(){
    //oid is unique identification ;data is response data; options is request function arguments;
    //const {oid,data,options} = await requestCache(axios,url)
    const {oid,data,options} = await requestCache(fetch,url,{method:"get"})
    console.log(oid,data)
}
setInterval(()=>{
    getData()//In fact,only one HTTP request occurred
},1000)

API

requestCache(request,...args)

  • request
    • type:function;such as axios,fetch ...
  • args
    • is request function option
  • return
    • Promise,and resolve result is a object {oid,data,options,status}

getCache()

  • return cache object

getCacheByOids(oids)

  • oids
    • type:string||number||array, is http request unique identification;
  • return
    • oids is string||number return a object
    • oids is array return a array

clearCache()

After clear cache, http request will be available

clearCacheByOids(oids)

Clear one or more HTTP request cache

  • oids
    • type:string||number||array, is http request unique identification;

request-cacher's People

Stargazers

 avatar

Watchers

 avatar

request-cacher's Issues

getCacheByOids should accept number or string

function getCacheByOids(oids) {
if (isNumber(oids) || isString(oids)) return cacheObj[oid];
if (Array.isArray(oids)) {
return oids.map((oid) => cacheObj[oid]);
}

it should be ->
if (isNumber(oids) || isString(oids)) return cacheObj[oids];

To accept the number or string cases

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.