views:

696

answers:

3

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.

+2  A: 

You need to use Fiddler to see what HTTP headers are sent by IE and your applications how these are different from ones for Firefox. What you have to have is to make browser send If-Modified-Since header (and possibly an ETag) header and your app should respond with HTTP 302 status.

Anton Gogolev
i was kinda hoping to get the help with the OutputCacheAttribute specifics 1st. but your suggestion will be invaluable in optimizing the HTTP headers. thanx
cottsak
+2  A: 

Try use ServerAndClient location:

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

Fujiy
A: 
ControllerContext.HttpContext.Response.ClearHeaders()
Scott