Skip to content

Debugging

At some point, you may encounter cache behavior that does not match expectations. To help diagnose such issues, the library provides a separate build with debug logging enabled.

You can use it by changing the setupCache import:

ts
import Axios from 'axios';

// Only import from `/dev` where you import `setupCache`.
import { setupCache } from 'axios-cache-interceptor';
import { setupCache } from 'axios-cache-interceptor/dev';

// same object, but with updated typings.
const axios = setupCache(Axios, {
  debug: console.log
});
ts
const Axios = require('axios');

// Only import from `/dev` where you import `setupCache`.
const { setupCache } = require('axios-cache-interceptor');
const { setupCache } = require('axios-cache-interceptor/dev');

// same object, but with updated typings.
const axios = setupCache(Axios, {
  debug: console.log
});
ts
const Axios = window.axios;

// Choose development bundle.
const { setupCache } = window.AxiosCacheInterceptor;

// same object, but with updated typings.
const axios = setupCache(Axios, {
  debug: console.log
});
ts
import Axios from 'https://cdn.skypack.dev/axios';

// Only import from `/dev` where you import `setupCache`.
import { setupCache } from 'https://cdn.skypack.dev/axios-cache-interceptor';
import { setupCache } from 'https://cdn.skypack.dev/axios-cache-interceptor/dev';

// same object, but with updated typings.
const axios = setupCache(Axios, {
  debug: console.log
});

And much more, depending on your context, situation, and configuration. Any misbehavior you encounter will have a log to explain it.

Sample of logs sent to console.
json
[
  {
    "id": "-644704205",
    "msg": "Sending request, waiting …",
    "data": { "overrideCache": false, "state": "empty" }
  },
  {
    "id": "-644704205",
    "msg": "Waiting list had a deferred for this key, waiting for it to finish"
  },
  {
    "id": "-644704205",
    "msg": "Detected concurrent request, waiting for it to finish"
  },
  {
    "id": "-644704205",
    "msg": "Useful response configuration found",
    "data": {
      "cacheConfig": {
        /*...*/
      },
      "cacheResponse": {
        "data": {
          /*...*/
        },
        "status": 200,
        "statusText": "OK",
        "headers": {
          /*...*/
        }
      }
    }
  },
  {
    "id": "-644704205",
    "msg": "Found waiting deferred(s) and resolved them"
  },
  {
    "id": "-644704205",
    "msg": "Returning cached response"
  },

  // First request ended, second call below:
  {
    "id": "-644704205",
    "msg": "Response cached",
    "data": {
      "cache": {
        /*...*/
      },
      "response": {
        /*...*/
      }
    }
  },
  {
    "id": "-644704205",
    "msg": "Returning cached response"
  }
]

Made with ❤️