0

每当我运行应用程序时,它第一次将 cacheMgr.cacheExists("myCache1") 返回为 true,但在重新启动服务器后它返回为 false。我无法理解这个问题。

EHCacheUtilty.java

private static Ehcache getCache(String cacheName) throws Exception{

        if(cacheMgr == null){
            try{
            cacheMgr = CacheManager.create(new URL("http://10.10.1.133:8080/ProjectName/xml/ehcache12.xml"));
            System.out.println("cacheMgr"+cacheMgr);
                System.out.println(cacheMgr.cacheExists("myCache1"));
                System.out.println(Arrays.asList(cacheMgr.getCacheNames()));
            }
            catch(Exception e){
                e.printStackTrace();
            }
        }

        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> 

请帮帮我

4

1 回答 1

0

每次重新启动服务器时,您都需要重新运行该程序(或者至少是其中初始化 EhCache 的部分)。重新启动服务器会消除您拥有的实例。

于 2013-04-02T02:38:00.840 回答