1 <%@ page import="javax.cache.CacheManager" %>
 2 <%@ page import="javax.cache.Caching" %>
 3 <%@ page import="javax.cache.Cache" %>
 4
 5 <h2>WSO2 Carbon Caching Demo</h2>
 6
 7 <hr/>
 8 <p>
 9
10 <h3>Add to Cache</h3>
11
12 <form action="index.jsp" method="POST">
13     <table border="0">
14         <tr>
15             <td>Key</td>
16             <td><input type="text" name="key"/></td>
17         </tr>
18         <tr>
19             <td>Value</td>
20             <td><input type="text" name="value"/></td>
21         </tr>
22         <tr>
23             <td>&nbsp;</td>
24             <td><input type="submit" value="Add" name="add"></td>
25         </tr>
26     </table>
27 </form>
28 </p>
29 <hr/>
30 <p>
31
32 <h3>Read from Cache</h3>
33
34 <form action="index.jsp" method="POST">
35     <table border="0">
36         <tr>
37             <td>Key</td>
38             <td><input type="text" name="key"/></td>
39         </tr>
40         <tr>
41             <td>&nbsp;</td>
42             <td><input type="submit" value="View" name="view"></td>
43         </tr>
44     </table>
45 </form>
46 </p>
47 <hr/>
48
49 <%
50     // The javax.cache.CacheManager instance used to obtain the cache
51     CacheManager cacheManager =   Caching.getCacheManagerFactory().getCacheManager("tsampleCacheManager");
52     Cache<String, String> cache = cacheManager.getCache("sampleCache");
53
54     if (request.getParameter("add") != null) {
55         String key = request.getParameter("key");
56         String value = request.getParameter("value");
57         cache.put(key, value);
58 %>
59 <p>
60     Added entry: <%= key %>
61 </p>
62 <%
63     } else if (request.getParameter("view") != null) {
64         String key = request.getParameter("key");
65         if (cache.get(key) != null) {
66             String content = (String) cache.get(key);
67             response.addHeader("cache-value", content);
68 %>
69             <p>
70                 Value of entry <%= key%> : <%= content %>
71             </p>
72 <%
73         } else {
74 %>
75             <p>
76                 Unable to find an entry by the given key <%= key%>!
77             </p>
78 <%
79         }
80     }
81 %>