Skip to content
This repository
Browse code

caching static pages

  • Loading branch information...
commit 1c20f62e146fd73b827c61c48dae661ed52e5771 1 parent 48f247d
Markiyan Matsekh authored November 14, 2012
8  src/EventStore/EventStore.Core/Services/Transport/Http/Configure.cs
@@ -49,9 +49,15 @@ public static ResponseConfiguration Ok(HttpEntity entity, Message message)
49 49
 
50 50
         public static ResponseConfiguration OkCache(HttpEntity entity, Message message, int seconds)
51 51
         {
  52
+            return OkCache(entity.ResponseCodec.ContentType, seconds);
  53
+        }
  54
+
  55
+        public static ResponseConfiguration OkCache(string contentType, int seconds)
  56
+        {
  57
+            // note MM: in old browsers Expires header maybe be required
52 58
             return new ResponseConfiguration(HttpStatusCode.OK,
53 59
                                              "OK",
54  
-                                             entity.ResponseCodec.ContentType,
  60
+                                             contentType,
55 61
                                              new KeyValuePair<string, string>("Cache-Control", string.Format("max-age={0}", seconds)));
56 62
         }
57 63
 
19  src/EventStore/EventStore.Core/Util/MiniWeb.cs
@@ -105,9 +105,15 @@ private void ReplyWithContent(HttpEntity http, string contentLocalPath)
105 105
                 }
106 106
                 else
107 107
                 {
  108
+                    var config = GetWebPageConfig(contentType);
108 109
                     var content = File.ReadAllBytes(fullPath);
109  
-                    http.Manager.Reply(content, 200, "OK", contentType, null, 
110  
-                        ex => _logger.InfoException(ex, "Error while replying from MiniWeb"));
  110
+
  111
+                    http.Manager.Reply(content,
  112
+                                       config.Code,
  113
+                                       config.Description,
  114
+                                       config.Type,
  115
+                                       config.Headers,
  116
+                                       ex => _logger.InfoException(ex, "Error while replying from MiniWeb"));
111 117
                 }
112 118
             }
113 119
             catch (Exception ex)
@@ -116,6 +122,15 @@ private void ReplyWithContent(HttpEntity http, string contentLocalPath)
116 122
             }
117 123
         }
118 124
 
  125
+        private static ResponseConfiguration GetWebPageConfig(string contentType)
  126
+        {
  127
+#if RELEASE || CACHE_WEB_CONTENT
  128
+            return Configure.OkCache(contentType, 60 * 60); //1 hour
  129
+#else
  130
+            return Configure.OkNoCache(contentType);
  131
+#endif
  132
+        }
  133
+
119 134
         public static string GetWebRootFileSystemDirectory(string debugPath = null)
120 135
         {
121 136
             string fileSystemWebRoot = null;
4  src/EventStore/EventStore.Web/es-common-web/js/es.tmpl.js
@@ -10,6 +10,10 @@ es.tmpl = (function () {
10 10
 
11 11
     registerOnLoad();
12 12
 
  13
+    $.ajaxSetup({
  14
+        cache: 'default' // prevent adding ?_=timestamp by jquery
  15
+    });
  16
+
13 17
     return {
14 18
         renderHead: renderHead,
15 19
         renderBody: renderBody,
2  src/EventStore/EventStore.Web/es-common-web/tmpl/_head.tmpl.html
... ...
@@ -1,4 +1,5 @@
1 1
     <meta charset="utf-8"/>
  2
+    <link rel="shortcut icon" href="/web/es/img/favicon.ico" type="image/x-icon" />
2 3
     <meta http-equiv="content-type" content="text/html; charset=utf-8" />
3 4
     
4 5
     <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
@@ -17,4 +18,3 @@
17 18
     <![endif]-->
18 19
 
19 20
     <!-- icons -->
20  
-<link rel="shortcut icon" href="/web/es/img/favicon.ico"/>

0 notes on commit 1c20f62

Please sign in to comment.
Something went wrong with that request. Please try again.