I have an a aspx page, but all content is generated by hands(yes I know that I need to make a handler, I have another question)
I want to cache output in client browser. Problem is that it's cached only for one query.
public static void ProceedCaching(string etag, string lastModify, string response, HttpResponse Response,
HttpRequest Request)
{
Response.AddHeader("ETag", "\"" + etag + "\"");
Response.AddHeader("Last-Modified", lastModify);
Response.AppendHeader("Cache-Control", "Public");
Response.AppendHeader("Expires",
DateTime.Now.AddMinutes(1).ToUniversalTime().ToString("r",DateTimeFormatInfo.InvariantInfo));
string ifModified = Request.Headers["If-Modified-Since"];
if (!string.IsNullOrEmpty(ifModified))
{
if (ifModified.Contains(";"))
ifModified = ifModified.Remove(ifModified.IndexOf(';'));
}
string incomingEtag = Request.Headers["If-None-Match"];
if (String.Compare(incomingEtag, etag) == 0 || string.Compare(ifModified, lastModify) == 0)
{
Response.StatusCode = 304;
Response.End();
}
Response.Write(response);
Response.End();
}
it's become preaty messy. As I said it's cached only once. After recevieng HTTP 304 browser will send clean request without caching information(etag, lastmodified). Have any ideas?
Found this answer here
Generally speaking, these are the most common rules that are followed (don’t worry if you don’t understand the details, it will be explained below):
And Microsoft has a good article if you don't want it to cache.