Cache forever, If the header of server response has no `cache-control`
ttkien opened this issue · 5 comments
ttkien commented
If the header of server response has no cache-control
field, the response will be cached forever. Because the expires
field will be undefined.
My suggestion is should treat the cases as maxAge:0 (no-cache)
axios-cache-adapter version: 2.5.0
DmitriyNikolenko commented
Same problem. cache age becomes uncontrolled
async function write (config, req, res) {
try {
const entry = {
expires: config.expires || Date.now(), // "|| Date.now()" can help
data: serialize(config, req, res)
}
ttkien commented
Same problem. cache age becomes uncontrolled
async function write (config, req, res) { try { const entry = { expires: config.expires || Date.now(), // "|| Date.now()" can help data: serialize(config, req, res) }
@DmitriyNikolenko I created Pull Request here. Please help me approve or vote it #169
java-james commented
+1 experiencing this issue.
java-james commented
My temp work around for anyone else depending on this lib:
// A response may be stored without an expiry if it's reading headers but none are present
// Use this custom invalidate to fix that issue until the related PR is merged
// https://github.com/RasCarlito/axios-cache-adapter/issues/168
const invalidate = async (config: any, request: AxiosRequestConfig): Promise<void> => {
if(isUndefined(request.url) || isUndefined(request.method)) {
return;
}
const method = request.method.toLowerCase();
const item = await config.store.getItem(request.url);
const shouldInvalidate = method !== "get" || (!isNull(item) && isUndefined(item.expires));
if (!shouldInvalidate) {
return;
}
await config.store.removeItem(config.uuid);
}
Deleted user commented
Should now be fixed in latest release https://github.com/RasCarlito/axios-cache-adapter/releases/tag/2.7.0