1 //Default cached seconds
2 int secondsTime = 100;
3
4 //Judge whether the last modification time is within the required time
5 //If the server-side file has not been modified, the return status is 304 and the content is empty, which saves the amount of data transmitted. If the server-side file has been modified, the return is similar to the first request.
6 if (["If-Modified-Since"] != null && ( - (["If-Modified-Since"]).Ticks).Seconds < secondsTime)
7 {
8 //Test code, here you will find that when the browser returns to the 304 status, the following date will not be output.
9 ();
10
11 = 304;
12 ("Content-Encoding", "gzip");
13 = "Not Modified";
14 }
15 else
16 {
17 //Output current time
18 ();
19
20 //Set client cache status
21 SetClientCaching(response, );
22 }
23
24 #region SetClientCaching..
25 /// <summary>
26 /// Set client cache status
27 /// </summary>
28 /// <param name="response"></param>
29 /// <param name="lastModified"></param>
30 private void SetClientCaching(HttpResponse response, DateTime lastModified)
31 {
32 (());
33 (lastModified);
34 //public to specify that the response can be cached by the client and shared (proxy) cache.
35 ();
36 // is the longest absolute time allowed to exist before a document is considered stale.
37 (new TimeSpan(7, 0, 0, 0));
38 //Set cache expiration from absolute time to adjustable time
39 (true);
40 }
41 #endregion