posted on 2012-08-30 09:33
xcp 阅读(4153)
评论(0) 编辑 收藏
ehcache.xml说明:
01.xml version="1.0" encoding="utf-8"?>
02.
03.
29.<ehcache xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"
30. xsi:nonamespaceschemalocation="ehcache.xsd" updatecheck="true"
31. monitoring="autodetect" dynamicconfig="true">
32.
33.
48. <diskstore path="java.io.tmpdir" />
49.
50.
51.
59.
60. <transactionmanagerlookup
61. class="net.sf.ehcache.transaction.manager.defaulttransactionmanagerlookup"
62. properties="" propertyseparator=":" />
63.
64.
74.
75. <cachemanagereventlistenerfactory
76. class="" properties="" />
77.
78.
101.
102.
103.
269.
270.
274. <defaultcache maxelementsinmemory="0" eternal="false"
275. overflowtodisk="true" timetoidleseconds="1200" timetoliveseconds="1200">
276.
277. defaultcache>
278.
279.
281.
282.
288. <cache name="samplecache1" maxelementsinmemory="10000"
289. maxelementsondisk="1000" eternal="false" overflowtodisk="true"
290. diskspoolbuffersizemb="20" timetoidleseconds="300" timetoliveseconds="600"
291. memorystoreevictionpolicy="lfu" />
292.
293.
294.
298. <cache name="samplecache2" maxelementsinmemory="1000" eternal="true"
299. overflowtodisk="false" memorystoreevictionpolicy="fifo" />
300.
301.
302.
305. <cache name="samplecache3" maxelementsinmemory="500" eternal="false"
306. overflowtodisk="true" timetoidleseconds="300" timetoliveseconds="600"
307. diskpersistent="true" diskexpirythreadintervalseconds="1"
308. memorystoreevictionpolicy="lfu" />
309.
310.
312. <cache name="sampleterracottacache" maxelementsinmemory="1000"
313. eternal="false" timetoidleseconds="3600" timetoliveseconds="1800"
314. overflowtodisk="false">
315.
316.
317. cache>
318.
319.
320.
321. <cache name="xacache" maxelementsinmemory="500" eternal="false"
322. timetoidleseconds="300" timetoliveseconds="600" overflowtodisk="false"
323. diskpersistent="false" diskexpirythreadintervalseconds="1">
324.
325. cache>
326.
327.
328.ehcache>
操作类实例
01.package com.rx;
02.
03.import java.io.serializable;
04.
05.import net.sf.ehcache.cache;
06.import net.sf.ehcache.cachemanager;
07.import net.sf.ehcache.element;
08.
09.publicclass ehcache {
10.
11. /**
12. * @param args
13. */
14. publicstaticvoid main(string[] args) {
15. system.out.println(1);
16. // cachemanager manager = new cachemanager();
17.
18. cachemanager singletonmanager = cachemanager.create();
19. cache memoryonlycache =new cache("testcache", 5000, false, false, 5, 2);
20. singletonmanager.addcache(memoryonlycache);
21. cache cache = singletonmanager.getcache("testcache");
22.
23. element element =new element("key1", "value1");
24. cache.put(element);
25. cache.put(new element("key1", "value2"));
26.
27. element = cache.get("key1");
28. serializable value = element.getvalue();
29. system.out.println(value);
30.
31. int elementsinmemory = cache.getsize();
32. system.out.println(elementsinmemory);
33.
34. long elementsinmemory2 = cache.getmemorystoresize();
35. system.out.println(elementsinmemory2);
36.
37. object obj = element.getobjectvalue();
38. cache.remove("key1");
39. system.out.println(obj);
40. singletonmanager.shutdown();
41. // manager.shutdown();
42.
43. system.out.println(2);
44.
45. }
46.
47.}
转自:
名称: ♪4c.esl | .↗evon
口号: 遇到新问题♪先要寻找一个方案乄而不是创造一个方案こ
mail: