How to reduce database load by caching

From Resin 3.0

Revision as of 23:23, 13 January 2009 by Ferg (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


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"/>

 </web-app>
Personal tools