I have this custom filter to compress the output of my pages:
public class EnableCompressionAttribute : ActionFilterAttribute { const CompressionMode compress = CompressionMode.Compress; public override void OnActionExecuting(ActionExecutingContext filterContext) { HttpRequestBase request = filterContext.HttpContext.Request; HttpResponseBase response = filterContext.HttpContext.Response; string acceptEncoding = request.Headers["Accept-Encoding"]; if (acceptEncoding == null) return; if (acceptEncoding.ToLower().Contains("gzip")) { response.Filter = new GZipStream(response.Filter, compress); response.AppendHeader("Content-Encoding", "gzip"); } else if (acceptEncoding.ToLower().Contains("deflate")) { response.Filter = new DeflateStream(response.Filter, compress); response.AppendHeader("Content-Encoding", "deflate"); } } }
I got the code from the book: Pro ASP.NET MVC V2 Framework (Expert Voice in .NET).
Now I have a mode of action similar to this:
[OutputCache(Order=1, Duration=300,VaryByParam="*", VaryByContentEncoding="gzip; deflate")] [EnableCompression(Order=0)] public ActionResult About() { return View(); }
How can I guarantee that the OutputCache filter caches compressed content? Will using the "Order" parameter, as in this example, be enough?
How can I find out what is happening in the cache?
Greetings.
UPDATE I tested Fiddler, apparently, it works no matter what order you use in the filters ... I get the first response with gzip and http.302 encoding in the following requests if the client is allowed to cache it or more http.200 with gzip encoding if only server allowed
Perhaps this is because OutputCache is the last filter by default, and there is no way to change it. Can anyone confirm this?
source share