Friday, May 15, 2015

MVC - Cache dynamic files in browser based on query string from action results

To cache we can do many things such as StaticCache in webconfig, HTML5 manifest cache and also we can use OutputCache in MVC.

To enable cache for dynamically changing contents. For ex, to load images based on file name and to cache use following attribute in controller or action.


        [HttpGet]
        [OutputCache(Duration = 600, VaryByParam = "imageFileName")]
        public FileResult GetSomeImageFile(string imageFileName)
        {
//your logic to load image file

 }

Here Duration mentioned in seconds and VaryByParam property to specify to cache based on parameter name 'imageFileName'

No comments:

Post a Comment