0
  1. 如何 <ehcache:eviction-advisor>在 ehcache.xml 文件中将 ehcache3 配置为“LFU”?如何实施public boolean adviseAgainstEviction(Object o, Object o2)EvictionAdvisorLFU 驱逐政策?

  2. 似乎 Spring 应用程序没有引用 ehcache.xml,即使该文件位于资源文件夹中,并且 application.properties 具有spring.cache.jcache.config=classpath:ehcache.xml.

  3. 进入 时AbstractCacheResolver,我看到的cacheManager是运行此代码时得到的,ConcurrentMapCacheManager而不是我得到的:EhcacheManager

URL myUrl = getClass().getResource("/ehcache.xml");
Configuration xmlConfig = new XmlConfiguration(myUrl);
CacheManager cacheManager = 
CacheManagerBuilder.newCacheManager(xmlConfig);
cacheManager.init();
distanceCache = cacheManager.getCache("distanceCache", LatLonDistance.class, Double.class);
  1. 如何确保我使用的是EhcacheManager而不是使用ConcurrentMapCacheManager

应用程序属性: spring.cache.jcache.config=classpath:ehcache.xml

也试过:spring.cache.ehcache.config=classpath:ehcache.xml

pom.xml:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.6.RELEASE</version>
</parent>

<dependency>
    <groupId>org.ehcache</groupId>
    <artifactId>ehcache</artifactId>
    <version>3.8.1</version>
</dependency>
<dependency>
    <groupId>javax.cache</groupId>
    <artifactId>cache-api</artifactId>
    <version>1.1.0</version>
</dependency>

ehcache.xml:

<ehcache:config
         xmlns:ehcache="http://www.ehcache.org/v3"
         xmlns:jcache="http://www.ehcache.org/v3/jsr107"
         xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
         xsi:schemaLocation="http://www.ehcache.org/v3 http://www.ehcache.org/schema/ehcache-core.xsd">

    <ehcache:cache alias="distanceCache">
        <ehcache:key-type>com.processing.utils.LatLonDistance</ehcache:key-type>
        <ehcache:value-type>java.lang.Double</ehcache:value-type>
      <ehcache:eviction-advisor>com.cache.LFUPolicy</ehcache:eviction-advisor>
        <ehcache:resources>
            <ehcache:heap unit="entries">2000000</ehcache:heap>

            <!--<offheap unit="MB">200</offheap>-->
        </ehcache:resources>
    </ehcache:cache>

</ehcache:config>
4

0 回答 0