0

我已经编写了下面的代码来获取 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 应用程序。有人可以解释这个问题吗?

4

0 回答 0