Bug: Setting an independent TTL for an individual request does not work
andrew2558 opened this issue · comments
What happened?
Setting an independent TTL for an individual request does not work.
below is my code:
axios setting:
const axios = setupCache(Axios, {
ttl: 10*60*1000,
interpretHeader: false,
});
request code:
function getNames() {
return new Promise((resolve, reject) => {
http(
"get",
GetNames,
{ cache: { ttl: 2 * 60 * 1000, override: true } }
).then(
(res) => {
resolve(res);
},
(error) => {
console.log("...", error);
reject(error);
}
);
});
}
When using the above request methods, the caching is not being utilized, and a GET request is sent every time upon clicking. What could be the problem?
I hope:
When setting an individual TTL parameter for a request, the caching duration of that request will be based on the specified TTL time instead of using the default global TTL configuration.
thank your very much
axios-cache-interceptor version
1.3.1
Node / Browser Version
v18.9.1 / chrome 118.0.5993.89
Axios Version
1.5.1
What storage is being used
Memory Storage
Relevant debugging log output
{
"data": {
"responseCode": 1,
"statusCode": 200,
"message": "Success",
"data": {
}
},
"status": 200,
"statusText": "",
"headers": {
"access-control-allow-credentials": "true",
"access-control-allow-headers": "Content-Type,Access-Token",
"access-control-allow-methods": "*",
"access-control-allow-origin": "*",
"access-control-expose-headers": "*",
"content-type": "application/json; charset=utf-8",
"date": "Fri, 27 Oct 2023 03:33:53 GMT",
"server": "Kestrel",
"x-axios-cache-stale-if-error": "120000"
},
"config": {
"transitional": {
"silentJSONParsing": true,
"forcedJSONParsing": true,
"clarifyTimeoutError": false
},
"adapter": [
"xhr",
"http"
],
"transformRequest": [
null
],
"transformResponse": [
null
],
"timeout": 100000,
"xsrfCookieName": "XSRF-TOKEN",
"xsrfHeaderName": "X-XSRF-TOKEN",
"maxContentLength": -1,
"maxBodyLength": -1,
"env": {},
"headers": {
"Authorization": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI2ZmM2NDZlMS0yNDE3LTRjYmEtOTAwZi1hM2Y3NTA3M2ZlNzgiLCJpYXQiOiIyMDIzLzkvMjMgOToyOTo1OSIsImh0dHA6Ly9zY2hlbWFzLnhtbHNvYXAub3J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ZWwuY29tIiwiQWRkYmVsLmNvbSIsIkFkZGJlbC5jb20iLCJBZGRiZWwuY29tIiwiQWRkYmVsLmNvbSIsIkFkZGJlbC5jb20iLCJBZGRiZWwuY29tIiwiQWRkYmVsLmNvbSIsIkFkZGJlbC5jb20iLCJBZGRiZWwuY29tIiwiQWRkYmVsLmNvbSIsIkFkZGJlbC5jb20iLCJBZGRiZWwuY29tIiwiQWRkYmVsLmNvbSIsIkFkZGJlbC5jb20iXX0.WxxiPDpUp1h6HHwRrtAJK4gkbGA3LWk-bxl5IL6z_GE",
"cache-control": "no-cache",
"pragma": "no-cache",
"expires": "0"
},
"cache": {
"update": {},
"ttl": 120000,
"methods": [
"get",
"head"
],
"cachePredicate": {},
"etag": true,
"modifiedSince": false,
"interpretHeader": false,
"cacheTakeover": true,
"staleIfError": true,
"override": true
},
"baseURL": "https://localhost:7047/api",
"params": {},
"method": "get",
"url": "/Setting/GetUserSetting",
"id": "-869087979",
"_retry": true
},
"request": {},
"id": "-869087979",
"cached": false
}
When I remove the parameter 'override: true'
, the individually set TTL is used as expected. Is this the reason for the behavior?
https://axios-cache-interceptor.js.org/config/request-specifics#cache-override
This option bypasses the current cache and always make a new http request. This will not delete the current cache, it will just replace the cache when the response arrives.
Please remove override: true if you want to cache your requests.