Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do i cache FileContentResult for performance?

Presently i have the following action to return files (images, PDF's, etc) from my DB:

    //
    // GET: /FileManager/GetFile/ID
    [OutputCache(Duration = 600, VaryByParam = "ID")]
    public ActionResult GetFile(int ID)
    {
        FileService svc = new FileService(new SqlFileRepository(base.ConnectionString));

        KsisOnline.Data.File result = svc.GetFileByID(ID);

        return File(result.Data, result.MimeType, result.UploadFileName);
    }

I'm using the OutputCache attribute but i dont know if i'm using it correctly or how to optimise it for this purpose.

As the code stands, i appear to get cache functionality in Firefox(3) but not IE(7). For some reason IE is requesting the image from the DB every time (which is killer bad obviously) and i dont know how to fix it. Sure IE doesn't support standards properly but maybe i'm still not following some preferred caching conventions. I'd really appreciate some help with this so i get minimal DB hits and caching support cross browser.

EDIT: To see the code above in action or to profile it yourself with browsers/tools, refer to this link.

like image 263
Matt Kocaj Avatar asked Apr 28 '09 07:04

Matt Kocaj


1 Answers

Try use ServerAndClient location:

[OutputCache(Duration=600, VaryByParam="ID", Location=OutputCacheLocation.ServerAndClient)]

like image 145
Felipe Pessoto Avatar answered Oct 14 '22 19:10

Felipe Pessoto