Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Caching of FileResult actions in MVC3

I have an action which returns a FileResult (which is a png image). I would dearly like for browsers to cache the result, because it doesn't change for a given request uri.

I have used routing to make the uri look like this-

http://localhost:6094/Map/Tiles/1.0.0/none/2/5/5.png 

And in the action method, i call:-

Response.Cache.SetCacheability(HttpCacheability.Public);

In Fiddler, I can observe that the response has the:-

Cache-control: public

header. Yet, subsequent requests for the same map tile look like this:-

    GET http://localhost:6094/Map/Tiles/1.0.0/none/2/5/5.png HTTP/1.1
Host: localhost:6094
Connection: keep-alive
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.34 Safari/536.11
Accept: */*
Referer: http://localhost:6094/
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-GB,en-US;q=0.8,en;q=0.6
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3

And so result in a 200 response, and the transfer of data.

Any idea why Chrome is not bothering to cache my data?

thanks

slip

like image 463
slippyr4 Avatar asked Jun 19 '12 15:06

slippyr4


1 Answers

Have you tried the OutputCache attribute? This should work fine for you but specify it's lifetime.

http://www.asp.net/mvc/tutorials/older-versions/controllers-and-routing/improving-performance-with-output-caching-cs

ex

[OutputCache(Duration=84600)]
like image 159
Adam Tuliper Avatar answered Oct 28 '22 23:10

Adam Tuliper