我已经编写了以下用于获取cacheManager对象的代码
public class EHCacheUtil implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
public static CacheManager cacheMgr = null;
private static Ehcache getCache(String cacheName) throws Exception{
if(cacheMgr == null){
File file = new File("F:\\ProjectWorkSpace\\src\\java\\ehcache.xml");
// We could use an environment or a VM variable
cacheMgr = CacheManager.create(new FileInputStream(file));
System.out.println("cacheMgr.cacheExists(cacheName)"+cacheMgr.cacheExists(cacheName));
}
Ehcache cache = null;
if(cacheMgr!=null){
//cache = cacheMgr.addCacheIfAbsent(name);
cache = cacheMgr.getEhcache(cacheName);
}
return cache;
}
ehcache.xml中
<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ehcache.sf.net/ehcache.xsd">
<diskStore path="G:\EHCacheTempMemory" />
<defaultCache maxElementsInMemory="10000" eternal="false"
overflowToDisk="true" timeToIdleSeconds="10" timeToLiveSeconds="20" diskPersistent="true" />
<cache name="myCache1"
maxElementsInMemory="500000"
maxElementsOnDisk="500000"
eternal="false"
overflowToDisk="true"
timeToIdleSeconds="864000"
timeToLiveSeconds="8640000"
diskPersistent="true"
diskSpoolBufferSizeMB="20"
diskExpiryThreadIntervalSeconds="8640000"
memoryStoreEvictionPolicy="LFU" />
</ehcache>
对于独立应用程序,SOP打印属实,但对于Web应用程序则不打印。 有人可以解释这个问题吗?