Caching Override: Private on ServiceStack

This is similar to the question Install Cache-Control: no-cache on GET requests that I did not answer.

In the API responses, the cache control header is set to private, and I'm sure I need No-Cache. I tried ResponseFilter but the value has not changed. It is not obvious when it is added or installed in the code or how to override it, so any guidance will be appreciated.

+4
source share
2 answers

In our current implementation, we install this manually in each service using Response.AddHeader(...). This is due to the fact that we want to control the expiration time of the cache for the service. I would be interested to learn cleaner ways to do this though.

Response.AddHeader(ServiceStack.Common.Web.HttpHeaders.CacheControl, String.Format("max-age={0}, public", ConfigurationManager.AppSettings["Cache.Expiration.Resource"]));
+2
source

I use the request filter attribute, which I apply to every 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");
    }
}
+7
source

All Articles