📄 cache.xtp
字号:
<s1 title="Server Caching"><p>Server caching can speed dynamic pages tonear-static speeds. Many pages created by databasequeries only change every 15 minutes or so, e.g. CNN or Slashdot.Resin can cache the results and serve them like static pages.</p><p>Resin's caching operates like a proxy cache. Every user shares the same cached page.</p><s2 title='Expires'><p>Setting the <var>Expires</var> header will cache the resultsuntil the time expires. For heavily loaded pages, even setting shortexpires times can significantly improve performance. Sessions shouldbe disabled for caching.</p><p>The following example sets expiration for 15 seconds. So thecounter should update slowly.</p><example title='Expires'><%@ page session=false %><%! int counter; %><%long now = System.currentTimeMillis();response.setDateHeader("Expires", now + 15000);%>Count: <%= counter++ %></example><p><var/Expires/> is useful for database generated pages which arecontinuously, but slowly updated. To cache based on something with a knownmodified date, like a file, you can use <var/If-Modified/>.</p></s2><s2 title='If-Modified'><p>The <var>If-Modified</var> headers let you cache based on anunderlying change date. For example, the page may only change when anunderlying source page changes. Resin lets you easily use <var>If-Modified</var> by overriding methods in HttpServlet orin a JSP page.</p><p>The following page only changes when the underlying 'test.xml'page changes.</p><example><%@ page session=false %><%!int counter;public long getLastModified(HttpServletRequest req){ String path = req.getRealPath("test.xml"); return new File(path).lastModified();}%>Count: <%= counter++ %></example></s2><s2 title='Included Pages'><p>Resin can cache subpages even when the top page can't be cached.Sites allowing user personalization will often design pages with<var/jsp:include/> subpages. Some subpages are user-specific and can'tbe cached. Others are common to everybody and can be cached.</p><p>Resin treats subpages as independent requests, so they can becached independent of the top-level page. Try the following, use thefirst <var/expires/> counter example as the included page. Create atop-level page that looks like:</p><example><%@ page session=true %><% if (! session.isNew()) { %><h1>Welcome back!</h1><% } %><jsp:include page="expires.jsp"/></example></s2></s1>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -