Skip to content

Commit

Permalink
caching static pages
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkiyanMatsekh committed Nov 14, 2012
1 parent 48f247d commit 1c20f62
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
Expand Up @@ -49,9 +49,15 @@ public static ResponseConfiguration Ok(HttpEntity entity, Message message)


public static ResponseConfiguration OkCache(HttpEntity entity, Message message, int seconds) public static ResponseConfiguration OkCache(HttpEntity entity, Message message, int seconds)
{ {
return OkCache(entity.ResponseCodec.ContentType, seconds);
}

public static ResponseConfiguration OkCache(string contentType, int seconds)
{
// note MM: in old browsers Expires header maybe be required
return new ResponseConfiguration(HttpStatusCode.OK, return new ResponseConfiguration(HttpStatusCode.OK,
"OK", "OK",
entity.ResponseCodec.ContentType, contentType,
new KeyValuePair<string, string>("Cache-Control", string.Format("max-age={0}", seconds))); new KeyValuePair<string, string>("Cache-Control", string.Format("max-age={0}", seconds)));
} }


Expand Down
19 changes: 17 additions & 2 deletions src/EventStore/EventStore.Core/Util/MiniWeb.cs
Expand Up @@ -105,9 +105,15 @@ private void ReplyWithContent(HttpEntity http, string contentLocalPath)
} }
else else
{ {
var config = GetWebPageConfig(contentType);
var content = File.ReadAllBytes(fullPath); var content = File.ReadAllBytes(fullPath);
http.Manager.Reply(content, 200, "OK", contentType, null,
ex => _logger.InfoException(ex, "Error while replying from MiniWeb")); http.Manager.Reply(content,
config.Code,
config.Description,
config.Type,
config.Headers,
ex => _logger.InfoException(ex, "Error while replying from MiniWeb"));
} }
} }
catch (Exception ex) catch (Exception ex)
Expand All @@ -116,6 +122,15 @@ private void ReplyWithContent(HttpEntity http, string contentLocalPath)
} }
} }


private static ResponseConfiguration GetWebPageConfig(string contentType)
{
#if RELEASE || CACHE_WEB_CONTENT
return Configure.OkCache(contentType, 60 * 60); //1 hour
#else
return Configure.OkNoCache(contentType);
#endif
}

public static string GetWebRootFileSystemDirectory(string debugPath = null) public static string GetWebRootFileSystemDirectory(string debugPath = null)
{ {
string fileSystemWebRoot = null; string fileSystemWebRoot = null;
Expand Down
4 changes: 4 additions & 0 deletions src/EventStore/EventStore.Web/es-common-web/js/es.tmpl.js
Expand Up @@ -10,6 +10,10 @@ es.tmpl = (function () {


registerOnLoad(); registerOnLoad();


$.ajaxSetup({
cache: 'default' // prevent adding ?_=timestamp by jquery
});

return { return {
renderHead: renderHead, renderHead: renderHead,
renderBody: renderBody, renderBody: renderBody,
Expand Down
@@ -1,4 +1,5 @@
 <meta charset="utf-8"/>  <meta charset="utf-8"/>
<link rel="shortcut icon" href="/web/es/img/favicon.ico" type="image/x-icon" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" /> <meta http-equiv="content-type" content="text/html; charset=utf-8" />


<meta name="viewport" content="width=device-width, initial-scale=1.0"/> <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
Expand All @@ -17,4 +18,3 @@
<![endif]--> <![endif]-->


<!-- icons --> <!-- icons -->
<link rel="shortcut icon" href="/web/es/img/favicon.ico"/>

0 comments on commit 1c20f62

Please sign in to comment.