Coder Social home page Coder Social logo

Comments (1)

arthurfiorette avatar arthurfiorette commented on June 15, 2024

Hey @paescuj is this directly impacting the performance of your app? Request and response in axios should have completely separated state from each other, that's why two finds happen.

I do not have time or a appealing reason to do such optimization this storage access should be almost irrelevant comparing to a network request which would happen always without axios-cache-interceptor.

However, I'm happy to guide you if you wanna work on it.

Let me walk you through what is currently happening in your usecase.

  1. Request is made, get() is called in the request interceptor.

let cache = await axios.storage.get(config.id, config);

  1. The storage wrapper detects the storage returned an stale entry with cached status, set() is called to also update this entry in the db.

await set(key, value, config);

  1. Everything is loaded to wait for a network response, a set() call is made to update this entry in the db to loading.

await axios.storage.set(
config.id,
{
state: 'loading',

  1. Request is sent to network, event 'Sending request, waiting for response' is emitted.

  2. Response arrives, the response interceptor has no real information of what happened before and has no state connection to the request interceptor, so another get() is performed.

const cache = await axios.storage.get(response.id, config);

  1. Response is processed and before returning, a set() is called to insert the response gotten from network.

await axios.storage.set(response.id, newCache, config);


However the use case you presented here probably have the highest ratio of db calls per request. Cached requests should have only a single get().

from axios-cache-interceptor.

Related Issues (20)

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.