1

我正在尝试使用 JCache(JSR 107)的 EHCache 实现,我在下面提供了以下配置文件src\main\resources\ehcache.xml

<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="ehcache.xsd" updateCheck="true" monitoring="autodetect"  dynamicConfig="true"> 
  <!-- see http://www.ehcache.org/ehcache.xml -->
  <defaultCache 
    maxEntriesLocalHeap="200000" 
    eternal="false"
    timeToIdleSeconds="1200"
    timeToLiveSeconds="1200">    
    <persistence strategy="localTempSwap"/>
  </defaultCache>
</ehcache>

这是我创建缓存的方法:

String providerName = "org.ehcache.jcache.JCacheCachingProvider";
CachingProvider cachingProvider = Caching.getCachingProvider(providerName);
CacheManager cacheManager = cachingProvider.getCacheManager();
CompleteConfiguration<ComposedKey, Object> config = new MutableConfiguration<ComposedKey, Object>()
    .setTypes(ComposedKey.class, Object.class)
    .setExpiryPolicyFactory(FactoryBuilder.factoryOf(new AccessedExpiryPolicy(new Duration(TimeUnit.MINUTES, 30))))
    .setReadThrough(false)
    .setWriteThrough(false)
    .addCacheEntryListenerConfiguration(
        new MutableCacheEntryListenerConfiguration<ComposedKey, Object>(new CacheListenerManagerJSR107Factory(), null, true,
            true));
;
Cache<ComposedKey, Object> cache = cacheManager.createCache("cache", config);

但似乎创建的缓存没有使用提供的配置(即在 下ehcache.xml),因为这里调试时是 ehcache 实例的属性:

[ name = orACJ2rF-1 status = STATUS_ALIVE eternal = false overflowToDisk = false maxEntriesLocalHeap = 1000 maxEntriesLocalDisk = 0 memoryStoreEvictionPolicy = LRU timeToLiveSeconds = 0 timeToIdleSeconds = 0 persistence = none diskExpiryThreadIntervalSeconds = 120 cacheEventListeners: org.ehcache.jcache.JCacheListenerAdapter ; orderedCacheEventListeners:  maxBytesLocalHeap = 0 overflowToOffHeap = false maxBytesLocalOffHeap = 0 maxBytesLocalDisk = 0 pinned = false ]
4

0 回答 0