wangjin
neo
Joined: 01/31/2013 01:21:38
Messages: 4
Offline
|
public static void main(String[] args) {
InputStream fis = null;
try {
fis = new FileInputStream(new File("src/ehcache.xml").getAbsolutePath());
CacheManager manager = new CacheManager(fis);
Ehcache cache = manager.getEhcache("shiro-activeSession");
Element element1 = new Element("1","a");
Element element2 = new Element("2","b");
Element element3 = new Element("3","c");
Element element4 = new Element("4","d");
Element element5 = new Element("5","e");
Element element6 = new Element("6","f");
cache.put(element1);
cache.put(element2);
cache.put(element3);
cache.put(element4);
cache.put(element5);
cache.put(element6);
boolean b1 =cache.isElementInMemory("1");
System.out.println(b1);
boolean b2 =cache.isElementInMemory("2");
System.out.println(b2);
boolean b3 =cache.isElementInMemory("3");
System.out.println(b3);
boolean b4 =cache.isElementInMemory("4");
System.out.println(b4);
boolean b5 =cache.isElementInMemory("5");
System.out.println(b5);
boolean b6 =cache.isElementInMemory("6");
System.out.println(b6);
boolean b7 =cache.isElementInMemory("7");
System.out.println(b7);
System.out.println("--------------------------");
boolean b11 =cache.isElementOnDisk("1");
System.out.println(b11);
boolean b22 =cache.isElementOnDisk("2");
System.out.println(b22);
boolean b33 =cache.isElementOnDisk("3");
System.out.println(b33);
boolean b44 =cache.isElementOnDisk("4");
System.out.println(b44);
boolean b55 =cache.isElementOnDisk("5");
System.out.println(b55);
boolean b66 =cache.isElementOnDisk("6");
System.out.println(b66);
boolean b77 =cache.isElementOnDisk("7");
System.out.println(b77);
} catch (FileNotFoundException e) {
e.printStackTrace();
} finally {
try {
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
上面的代码是为了测试元素是否会缓存到磁盘用的,我的配置文件如下:
<cache name="shiro-activeSession"
maxElementsInMemory="5"
eternal="false"
timeToIdleSeconds="1200"
timeToLiveSeconds="1200"
overflowToDisk="true"
diskPersistent="false"
maxElementsOnDisk="1"
diskExpiryThreadIntervalSeconds="60"
/>
让我很奇怪的是,如果上面的代码直接执行的话,返回结果是:
true
true
true
true
true
false
false
--------------------------
true
true
true
true
true
true
false
如果我不是直接执行,而是debug执行,在第一句加断点,分步执行,结果如下:
true
true
true
true
true
false
false
--------------------------
false
false
false
false
false
true
false
为什么会是这样?
|