This is similar to question Set Cache-Control: no-cache on GET requests, which wasn't really answered.
In the API responses, the cache-control header is being set to private, and I'm pretty sure I need No-Cache. I tried a ResponseFilter, but the value didn't change. It's not obvious where this is being added or set in the code or how to override, so any guidance would be appreciated.
I use a request filter attribute that I apply to each service or method that should not be cached on the client.
public class NoCacheAttribute : RequestFilterAttribute
{
public override void Execute(IHttpRequest req, IHttpResponse res, object responseDto)
{
res.AddHeader(HttpHeaders.CacheControl, "no-store,must-revalidate,no-cache,max-age=0");
}
}
In our current implementation we are setting this manually in each service using Response.AddHeader(...)
. This is because we want to control the cache expiration time per service. I would be interested in learning cleaner ways of doing this though.
Response.AddHeader(ServiceStack.Common.Web.HttpHeaders.CacheControl, String.Format("max-age={0}, public", ConfigurationManager.AppSettings["Cache.Expiration.Resource"]));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With