How to reduce database load by caching

From Resin 3.0

(Difference between revisions)
Jump to: navigation, search
(New page: Category: HowTo === cache.jsp === <%@ page import="com.caucho.cluster.*" %> <%! @javax.webbeans.Current Cache _cache; %> <% String value = (String) _cache.get("my-key"...)
 
(WEB-INF/resin-web.xml)
Line 24: Line 24:
 
                       xmlns:cluster="urn:java:com.caucho.cluster">
 
                       xmlns:cluster="urn:java:com.caucho.cluster">
 
   
 
   
       <cluster:TriadCache name="my-cache"/>
+
       <cluster:TriadCache name="my-cache"
 +
                                          expire-timeout="10m"/>
 
   
 
   
 
   </web-app>
 
   </web-app>

Revision as of 07:25, 14 January 2009


cache.jsp

 <%@ page import="com.caucho.cluster.*" %>
 <%! @javax.webbeans.Current Cache _cache; %>
 <%
        String value = (String) _cache.get("my-key");
        if (value != null) {
           out.println("old: " + value);
        }
        else {
            value = calculate_slow_value();
            _cache.put("my-key", value);

           out.println("new: " + value);
       }
 %>

WEB-INF/resin-web.xml

 <web-app xmlns="http://caucho.com/ns/resin"
                     xmlns:cluster="urn:java:com.caucho.cluster">

     <cluster:TriadCache name="my-cache"
                                         expire-timeout="10m"/>

 </web-app>
Personal tools