My web-site returns information for items which it takes from disk (involving some logic located in the controller, so it is not just static assets). I tried to optimize it by returning 304 for items which are not changed, by getting file write time for the corresponding item. Now, after I update the code, my application still thinks that an item is not updated and returns 304 - it does not realize that application code is changed so the result would be different. Because of that users do not see the update immediately, only after they get rid of their cache. I would like to solve that problem by checking not only 'item update time' but also 'application update time'. Is there a way to get something like time when application was updated? By this time I would like to see kind of maximum of update times of all application files.
UPD: As asked for example code, here is slightly simplified version:
public static DateTime? LastKnownDate(this HttpRequestBase request)
{
if (!string.IsNullOrEmpty(request.Headers["If-Modified-Since"]))
{
var provider = CultureInfo.InvariantCulture;
DateTime date;
if (DateTime.TryParse(
request.Headers["If-Modified-Since"],
provider,
DateTimeStyles.RoundtripKind,
out date)) return date;
}
return null;
}
public ActionResult Test(int id)
{
var path = @"C:\data\" + id;
var file = new FileInfo(path);
if (!file.Exists) return HttpNotFound();
var date = Request.LastKnownDate();
if (date != null && date >= file.LastWriteTimeUtc)
{
return Response.NotModified();
}
Response.AddHeader("Last-Modified", file.LastWriteTimeUtc.ToString("o"));
return File(path, "application/octet-stream");
}