tsed icon indicating copy to clipboard operation
tsed copied to clipboard

Option to disable cache control when caching endpoints

Open pdeveltere opened this issue 6 months ago • 0 comments

Is your feature request related to a problem? Please describe.

Currently when caching an enpoint response with @UseCache, the cache-control header is set with the ttl of that cache.

The problem we are facing is that our server side caching is different from the client side caching: We have an endpoint that returns data based on the accept-language header, which represent the language our app is in. On the server, we cache the response, based on the accept-language header. The problem here is that any http client by default the cache-control header will take precedence over the accept-language , leading to an issue that the response will stay in the previous language even if the apps switched language.

To be able to resolve this issue we ask for the possibility to have more control over this cache-control header when configuring the cache 🙏🏽

Describe the solution you'd like

A new configuration like this:

@Configuration({
    cache: {
        disableCacheControl: true;
    } 
})

and then change it in the cache interceptor:

if (!this.disableCacheControl) {
   const calculatedTTL = this.cache.calculateTTL(result, ttl);

   $ctx.response.setHeaders({
     "cache-control": `max-age=${calculatedTTL}`
   });
}

Describe alternatives you've considered

No response

Additional context

No response

Acceptance criteria

No response

pdeveltere avatar Aug 01 '24 11:08 pdeveltere