相关疑难解决方法(0)

另一个未命名的CacheManager已经存在于同一个VM中(ehCache 2.5)

这是我运行junit测试时会发生的事情......

Another CacheManager with same name 'cacheManager' already exists in the same VM. Please 
provide unique names for each CacheManager in the config or do one of following:
1. Use one of the CacheManager.create() static factory methods to reuse same
   CacheManager with same name or create one if necessary
2. Shutdown the earlier cacheManager before creating new one with same name.

The source of the existing CacheManager is: 
 DefaultConfigurationSource [ ehcache.xml or ehcache-failsafe.xml ]
Run Code Online (Sandbox Code Playgroud)

异常背后的原因是什么?可以同时运行多个cacheManager吗?

这就是我使用Sping 3.1.1配置cachManager的方法.它将cacheManager的范围明确设置为"singleton"

<ehcache:annotation-driven />

<bean …
Run Code Online (Sandbox Code Playgroud)

junit spring ehcache

73
推荐指数
6
解决办法
7万
查看次数

Ehcache磁盘存储不干净关机

我正在使用具有磁盘存储持久性的缓存.在应用程序的后续重新运行中,我收到以下错误:

net.sf.ehcache.store.DiskStore deleteIndexIfCorrupt
WARNING: The index for data file MyCache.data is out of date,
probably due to an unclean shutdown. Deleting index file MYCache.index
Run Code Online (Sandbox Code Playgroud)

有没有办法解决这个问题,除了明确调用net.sf.ehcache.CacheManager.shutdown()应用程序中的某个地方?

缓存配置:

<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="ehcache.xsd"
             updateCheck="true" monitoring="autodetect">

    <diskStore path="C:\work"/>

    <cacheManagerEventListenerFactory class="" properties=""/>

    <cacheManagerPeerProviderFactory
            class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
            properties="peerDiscovery=automatic,
                        multicastGroupAddress=230.0.0.1,
                        multicastGroupPort=4446, timeToLive=1"
            propertySeparator=","
            />

    <cacheManagerPeerListenerFactory
            class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"/>

    <defaultCache
            maxElementsInMemory="1"
            eternal="false"
            timeToIdleSeconds="0"
            timeToLiveSeconds="86400"
            overflowToDisk="true"
            diskSpoolBufferSizeMB="1"
            maxElementsOnDisk="10000"
            diskPersistent="true"
            diskExpiryThreadIntervalSeconds="120"
            memoryStoreEvictionPolicy="LFU"
            />

</ehcache>
Run Code Online (Sandbox Code Playgroud)

用于复制问题的代码:

import java.util.ArrayList;
import java.util.List;

import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;

public class CacheTest {
    static CacheManager manager = …
Run Code Online (Sandbox Code Playgroud)

java ehcache

6
推荐指数
1
解决办法
1万
查看次数

防止ehcache在启动时尝试访问互联网

我有一个相当简单的非集群应用程序运行带有spring和hibernate的ehcache.

在启动时我收到此错误:

<06-Sep-2010 19:14:05 o'clock BST> <Error> <Net>  <Failed to communicate with proxy:   10.x.x.x/8080. Will try connection www.terracotta.org/80 now.
Run Code Online (Sandbox Code Playgroud)

java.net.SocketTimeoutException:连接超时

如何阻止此通话?

这是我的ehcache.xml:

<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:noNamespaceSchemaLocation="ehcache.xsd"
         updateCheck="false" monitoring="off" dynamicConfig="false">


<defaultCache maxElementsInMemory="1000" eternal="false"
    timeToIdleSeconds="60" timeToLiveSeconds="60"
     overflowToDisk="false" >
      <terracotta clustered="false"/>
</defaultCache>
Run Code Online (Sandbox Code Playgroud)

我确信这个ehcache.xml被拾取并使用,例如没有类路径问题.

我正在使用:ehcache 2.0.1和hibernate 3.3.1.GA

java spring hibernate ehcache

6
推荐指数
1
解决办法
7919
查看次数

使用Spring Cache实现多个缓存实现

我正在开发一个Spring Boot应用程序,我需要使用分布式(例如Hazelcast)和本地(例如Guava)缓存.有没有办法配置Spring Cache在使用时使用它们@Cacheable并根据缓存名称决定需要哪个实现?

我尝试为HZ和Guava创建一个配置来定义里面的缓存名称,但是Spring抱怨它无法找到应该由HZ处理的缓存名称.当我独家使用HZ或Guava时,它们起作用.

java spring caching spring-boot spring-cache

5
推荐指数
1
解决办法
9974
查看次数

如何在没有xml的情况下使用spring boot 2和ehcache 3?

现在我有以下配置:

@Configuration
@EnableCaching
public class EhcacheConfig {
    @Bean
    public CacheManager cacheManager() throws URISyntaxException {
        return new JCacheCacheManager(Caching.getCachingProvider().getCacheManager(
                getClass().getResource("/ehcache.xml").toURI(),
                getClass().getClassLoader()
        ));
    }
}
Run Code Online (Sandbox Code Playgroud)

它指的是以下 XML:

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

    <cache alias="pow_cache">
        <key-type>org.springframework.cache.interceptor.SimpleKey</key-type>
        <value-type>java.lang.Double</value-type>
        <expiry>
            <ttl unit="seconds">15</ttl>
        </expiry>

        <listeners>
            <listener>
                <class>my.pack.CacheEventLogger</class>
                <event-firing-mode>ASYNCHRONOUS</event-firing-mode>
                <event-ordering-mode>UNORDERED</event-ordering-mode>
                <events-to-fire-on>CREATED</events-to-fire-on>
                <events-to-fire-on>EXPIRED</events-to-fire-on>
            </listener>
        </listeners>

        <resources>
            <heap unit="entries">2</heap>
            <offheap unit="MB">10</offheap>
        </resources>
    </cache>

</config>
Run Code Online (Sandbox Code Playgroud)

服务看起来像这样:

@Cacheable(value = "pow_cache", unless = "#pow==3||#result>100", condition = "#val<5")
public Double pow(int val, int pow) throws InterruptedException {
    System.out.println(String.format("REAL invocation myService.pow(%s, …
Run Code Online (Sandbox Code Playgroud)

java ehcache spring-boot spring-cache ehcache-3

5
推荐指数
2
解决办法
6056
查看次数