标签: ehcache

Hibernate + EhCache = java.io.NotSerializableException

我现在正在进行负载测试.大约900个请求后,我收到此错误:

[ 03.08.10 11:49:00.465] [Store org.hibernate.cache.StandardQueryCache Spool Thread] ERROR net.sf.ehcache.store.DiskStore  - org.hibernate.cache.StandardQueryCacheCache: Failed to write element to disk 'sql: select hotelfeatu0_.name as col_0_0_ from feature hotelfeatu0_ where hotelfeatu0_.class='org.company.domains.HotelFeatures' and hotelfeatu0_.lang=? and hotelfeatu0_.hotel_id=?; parameters: ; named parameters: {ht=100: 'Hotel', lng=en}'. Initial cause was org.company.domains.Hotel
java.io.NotSerializableException: org.company.domains.Hotel
    at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1156)
    at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1509)
    at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1474)
    at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1392)
    at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1150)
    at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:326)
    at java.util.HashMap.writeObject(HashMap.java:1001)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:945)
    at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1461)
    at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1392)
    at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1150)
    at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1509)
    at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1474) …
Run Code Online (Sandbox Code Playgroud)

java grails hibernate ehcache

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

为Spring3.1.1和Hibernate配置EHCache

我试图在使用Hibernate 3.5.5的现有Spring 3.1.1应用程序中启用对象缓存.我使用的是ehcache 2.2.0.在我的applicationContext中,我添加了配置以使用EHCache切换缓存.

<cache:annotation-driven />
<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager"
    p:cache-manager="ehcache" />
<bean id="ehcache"
    class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"
    p:config-location="ehcache.xml" />
Run Code Online (Sandbox Code Playgroud)

然后我创建了ehcache.xml文件:

<diskStore path="java.io.tmpdir" />

<defaultCache 
    eternal="false" 
    maxElementsInMemory="1000"
    overflowToDisk="false" 
    diskPersistent="false" 
    timeToIdleSeconds="0"
    timeToLiveSeconds="0" 
    memoryStoreEvictionPolicy="LRU"/>

<cache name="studentCache" 
    eternal="false"
    maxElementsInMemory="10000" 
    overflowToDisk="false" 
    diskPersistent="false"
    timeToIdleSeconds="0" 
    timeToLiveSeconds="0"
    memoryStoreEvictionPolicy="LRU" /> 
Run Code Online (Sandbox Code Playgroud)

我在ehcache的pom.xml文件中添加了必要的依赖项.但是现在我收到了这个错误:

Initialization of bean failed; 
nested exception is org.springframework.beans.ConversionNotSupportedException: 
Failed to convert property value of type 'java.lang.String' to required type
'net.sf.ehcache.CacheManager' for property 'cacheManager'; 
nested exception is java.lang.IllegalStateException: 
Cannot convert value of type [java.lang.String] to required type
[net.sf.ehcache.CacheManager] for property 'cacheManager': 
no …

java spring hibernate ehcache

11
推荐指数
2
解决办法
2万
查看次数

设置ehcache复制 - 我需要哪些多播设置?

我想设置为记录在这里的Ehcache复制:http://ehcache.sourceforge.net/EhcacheUserGuide.html#id.s22.2
这是在Windows机器上,但在生产中在Solaris将最终运行.

说明如下设置提供者:

 <cacheManagerPeerProviderFactory
     class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
     properties="peerDiscovery=automatic, multicastGroupAddress=230.0.0.1,
     multicastGroupPort=4446, timeToLive=32"/>
Run Code Online (Sandbox Code Playgroud)

像这样的倾听者:

<cacheManagerPeerListenerFactory
    class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
    properties="hostName=localhost, port=40001,
    socketTimeoutMillis=2000"/>
Run Code Online (Sandbox Code Playgroud)

我的问题是:
多播IP地址和端口是否是任意的(我知道地址必须在特定范围内,但它们必须是特定的数字)?
它们是否需要由我们的系统管理员以某种方式设置(我在办公室网络上)?

我想在本地测试它,所以使用上面的配置运行两个单独的tomcat实例.我需要在每个方面做些什么改变?我知道两个听众都听不到同一个端口 - 但提供商怎么样?
另外,侦听器端口是否也是任意的?

我已经尝试过如上设置,但在我的测试中,缓存似乎没有被复制 - 在一个tomcat的缓存中添加的值不存在于另一个缓存中.
我可以做些什么来调试这种情况(除了数据包嗅探)?

在此先感谢任何帮助,一直在我的头发上撕裂!

java multicast ehcache

10
推荐指数
2
解决办法
2万
查看次数

有没有办法配置Amazon EC2实例以支持EhCache所需的多播发现

有没有办法配置Amazon EC2实例以支持EhCache自动发现所需的多播?(通过iptables hacks等)/

multicast ehcache amazon-ec2

10
推荐指数
1
解决办法
9287
查看次数

在两个webapps之间共享Ehcache

我有2个webapps,一个管理员webapp,以及实际的应用程序webapp本身.两者共享对mysql存储的访问权限,而Ehcache用于缓存用户详细信息,以防止用户按REST API请求查找后端.

我的问题是可以使用管理员应用程序(很少我会添加)来更新用户凭据,让我们说密码或用户名,或更改一些授权级别等.现在,当发生这种情况时,我需要用户缓存无效或清除,以便主用户可以在用户查找时访问数据库,以便将新用户详细信息放入缓存中.

目前正在发生这种情况,但主客户端webapp无法清除缓存.

如何在两个webapps之间共享一个ehcache(在jetty或tomcat中托管)?我目前正在使用Jetty,但计划切换到Tomcat.

我正在使用Spring 3,Jersey,Hibernate,MySQL和Google Ehcache注释.

谢谢你的帮助.

rest tomcat web-applications ehcache jersey

10
推荐指数
2
解决办法
3759
查看次数

简单的Java缓存库或设计模式?

我需要经常访问耗时计算的结果.结果不经常更改,因此我不得不不时重新计算数据,但可以暂时使用过时的结果.最简单的方法是什么?现有的库方法或设计模式是什么?

我在想类似的东西

private static List myCachedList = null;

...

// refresh list once in 3600 seconds
if (needsRefresh(myCachedList, 3600)) {
    // run the calculation
    myCachedList = ...
}
// use either updated or previous value from here on
Run Code Online (Sandbox Code Playgroud)

一个正确的实现可能不是微不足道的,它可能必须处理线程安全,竞争条件等,所以我宁愿使用一个经过验证的实现,而不是在我自己.

java memcached caching design-patterns ehcache

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

基于日期的ehcache

我正在使用ehcache 2.5.4.

我有一个对象需要在白天缓存,并在每天00:00 am刷新一个新值.

目前使用ehcache配置我只能设置生存时间和空闲时间,但这取决于我创建对象的时间或使用时间.即:

    <cache
    name="cache.expiry.application.date_status"
    maxElementsInMemory="10"
    eternal="false"
    timeToIdleSeconds="60"
    timeToLiveSeconds="50" />
Run Code Online (Sandbox Code Playgroud)

有没有办法让ehcache根据特定时间使特定缓存过期.

java caching hibernate ehcache

10
推荐指数
2
解决办法
5449
查看次数

如何在使用Hibernate时删除Ehcache WARN消息

我有这个Ehcache XML配置:

<ehcache>
    <defaultCache
            maxElementsInMemory="10000"
            eternal="false"
            timeToIdleSeconds="120"
            timeToLiveSeconds="120"
            overflowToDisk="false"
            diskSpoolBufferSizeMB="30"
            diskPersistent="false"
            diskExpiryThreadIntervalSeconds="120"
            memoryStoreEvictionPolicy="LRU"
            />
</ehcache>
Run Code Online (Sandbox Code Playgroud)

而且,我有一些实体包(大约150个).如果我在tomcat服务器上部署我的应用程序,日志中会有很多WARN消息:

2015-04-29 11:59:02,712 [RMI TCP连接(3)-127.0.0.1] WARN org.hibernate.cache.ehcache.AbstractEhcacheRegionFactory - HHH020003:无法找到名为[com.company的缓存的特定ehcache配置. project.entity.package.MyEntity]; 使用默认值.

我可以为每个实体编写配置 -

<cache name="com.company.project.entity.package.MyEntity"
                      maxEntriesLocalHeap="50"
                      eternal="false"
                      overflowToDisk="false"
                    timeToLiveSeconds="120">
                <persistence strategy="localTempSwap"/>
        </cache>
Run Code Online (Sandbox Code Playgroud)

但是这样,我的配置文件变得太大(1600行).我认为存在另一种方法来为每个实体设置默认配置并终止警告消息,但我不知道该怎么做.如果有人知道,请帮忙.非常感谢.

java configuration logging hibernate ehcache

10
推荐指数
1
解决办法
9537
查看次数

Play 2.4测试出错:CacheManager已关闭.它不能再使用了

我们的应用程序基于Play 2.4与Scala 2.11和Akka构建.使用的数据库是MySQL.

缓存在我们的应用程序中大量使用.我们使用Play的默认EhCache进行缓存.

我们的示例代码段:

import play.api.Play.current
import play.api.cache.Cache

case class Sample(var id: Option[String],
                 //.. other fields
)

class SampleTable(tag: Tag)
  extends Table[Sample](tag, "SAMPLE") {
  def id = column[Option[String]]("id", O.PrimaryKey)
  // .. other field defs
}

object SampleDAO extends TableQuery(new SampleTable(_)) with SQLWrapper {
  def get(id: String) : Future[Sample] = {
    val cacheKey = // our code to generate a unique cache key
    Cache.getOrElse[Future[[Sample]](cacheKey) {
      db.run(this.filter(_.id === id).result.headOption)
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

我们使用Play的内置Specs2进行测试. …

junit caching ehcache scala-2.11 playframework-2.4

10
推荐指数
1
解决办法
2688
查看次数

为什么我的实体不会从我的二级缓存中被逐出?

我正在使用Hibernate 4.3.11.Final和Spring 3.2.11.RELEASE.我很困惑为什么我的缓存驱逐不起作用.我在DAO中设置了这个...

@Override
@Caching(evict = { @CacheEvict("main") })
public Organization save(Organization organization)
{
    return (Organization) super.save(organization);
}

@Override
@Cacheable(value = "main")
public Organization findById(String id)
{
    return super.find(id);
}
Run Code Online (Sandbox Code Playgroud)

这是我的Spring配置......

<cache:annotation-driven key-generator="cacheKeyGenerator" />

<bean id="cacheKeyGenerator" class="org.mainco.subco.myproject.util.CacheKeyGenerator" />

<bean id="cacheManager"
    class="org.springframework.cache.ehcache.EhCacheCacheManager"
    p:cacheManager-ref="ehcache"/>

<bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"
    p:configLocation="classpath:ehcache.xml"
    p:shared="true" />

<util:map id="jpaPropertyMap">
    <entry key="hibernate.show_sql" value="true" />
    <entry key="hibernate.dialect" value="org.mainco.subco.myproject.jpa.subcoMysql5Dialect" />
    <entry key="hibernate.cache.region.factory_class" value="org.hibernate.cache.ehcache.EhCacheRegionFactory" />
    <entry key="hibernate.cache.provider_class" value="org.hibernate.cache.EhCacheProvider" />
    <entry key="hibernate.cache.use_second_level_cache" value="true" />
    <entry key="hibernate.cache.use_query_cache" value="false" />
    <entry key="hibernate.generate_statistics" value="true" />
    <entry key="javax.persistence.sharedCache.mode" …
Run Code Online (Sandbox Code Playgroud)

spring hibernate ehcache second-level-cache evict

10
推荐指数
1
解决办法
1583
查看次数