哪个更适合以下环境:
我现在会倒出脑子里的东西.我可能错了.
我知道Redis需要一个单独的服务器(?),Ehcache提供本地缓存,因此它必须更快,但会跨服务器复制缓存(?).使用Ehcache可以在更新一个缓存后更新所有缓存.
我的问题是哪个更符合我提到的环境?
谁的表现会更好,或者什么样的表现可能比另一个表现更好?
提前致谢.
我已经为EHCache配置了一个defaultCache(用于元素),一个StandardQueryCache(用于查询)和UpdateTimestampsCache(我认为是为了跟踪数据库更新......但我并没有真正得到它所做的一切).
我为每个缓存设置了maxElementsInMemory,但我没有得到的是这个数字控制StandardQueryCache和UpdateTimestampsCache的内容.我知道可以在默认缓存中缓存的实体数量不得超过10000,但查询缓存不会缓存元素.它缓存主键(据我所知).
这是否意味着StandardQueryCache的maxElementsInMemory控制结果中的"行"数,或者它是否控制了它可能具有的元素的主键对数?
那么UpdateTimestampsCache呢?它是否跟踪实体上次更新的时间,上次更新表的时间......或其他内容?我应该为maxElementsInMemory使用哪个号码?
谢谢!
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="ehcache.xsd" updateCheck="true" monitoring="autodetect" dynamicConfig="true">
<defaultCache
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="3600"
timeToLiveSeconds="3600">
</defaultCache>
<cache
name="org.hibernate.cache.internal.StandardQueryCache"
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="3600"
timeToLiveSeconds="3600">
</cache>
<cache
name="org.hibernate.cache.spi.UpdateTimestampsCache"
maxElementsInMemory="10000"
eternal="true">
</cache>
</ehcache>
Run Code Online (Sandbox Code Playgroud) 我找到了一些如何配置纯hibernate以使用EHCache的说明.但我找不到任何说明如何配置JPA2.0 EntityManager来使用缓存.Hibernate 3.5.2是我的JPA2.0提供程序.
编辑// @Cacheable(true)
对于实体来说足够了吗?或者我应该使用@org.hibernate.annotations.Cache
配置实体?
我想用最新的hibernate,hibernate-annotations和ehcache依赖项来更新我的Maven pom.xml.
我阅读了hibernate下载页面和ehcache donwload页面.我试图解释它似乎都失败了.有人可以写出应该进入pom.xml的片段吗?
Cryptic hibernate下载页面:http: //hibernate.org/downloads
Cryptic ehcache下载页面:http: //www.terracotta.org/dl/ehcache-oss-download-catalog
这是我到目前为止:
<properties>
<hibernate.version>3.6.0.Final</hibernate.version>
</properties>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
<exclusions>
<exclusion>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
</exclusion>
<exclusion>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-ehcache</artifactId>
<version>${hibernate.version}</version>
<exclusions>
<exclusion>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>2.2.0</version>
<type>pom</type>
</dependency>
</dependencies>
<repositories>
<repository>
<id>codehaus-repository</id>
<name>Codehaus</name>
<url>https://nexus.codehaus.org/content/repositories/releases/</url>
<layout>default</layout>
</repository>
<repository>
<id>java.net</id>
<url>http://download.java.net/maven/1</url>
<layout>legacy</layout>
</repository>
<repository>
<id>central</id>
<name>Maven Repository Switchboard</name>
<layout>default</layout>
<url>http://repo1.maven.org/maven2</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>sonatype-ehcache</id>
<url>http://oss.sonatype.org/content/repositories/sourceforge-releases</url>
<layout>default</layout>
</repository> …
Run Code Online (Sandbox Code Playgroud) 我遇到了以下问题.
我的项目中有一套测试服,每个测试都运行良好.
但是,当我将它们作为套件运行时,我们中的一些会因以下异常而失败:
Caused by: java.lang.IllegalStateException: The dao Cache is not alive (STATUS_SHUTDOWN)
at net.sf.ehcache.Cache$CacheStatus.checkAlive(Cache.java:4269)
at net.sf.ehcache.Cache.checkStatus(Cache.java:2703)
at net.sf.ehcache.Cache.get(Cache.java:1576)
at org.springframework.cache.ehcache.EhCacheCache.get(EhCacheCache.java:61)
at org.springframework.cache.interceptor.CacheAspectSupport.inspectCacheables(CacheAspectSupport.java:310)
at org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:198)
at org.springframework.cache.interceptor.CacheInterceptor.invoke(CacheInterceptor.java:66)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:90)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
Run Code Online (Sandbox Code Playgroud)
有没有办法避免这种行为,即在多次测试中保持缓存活着还是正确关闭?
我希望@Cacheable
在没有参数的方法上有注释.在这种情况下,我使用@Cacheable如下
@Cacheable(value="usercache", key = "mykey")
public string sayHello(){
return "test"
}
Run Code Online (Sandbox Code Playgroud)
但是,当我调用此方法时,它不会被执行,并且如下所示会出现异常
org.springframework.expression.spel.SpelEvaluationException:EL1008E:(pos 0):在'org.springframework.cache.interceptor.CacheExpressionRootObject'类型的对象上找不到属性或字段'mykey' - 可能不公开?
请建议.
从这里和整个网络搜索看来,不可能将EHCache实现为Hibernate的后写缓存,因为这需要对Hibernate代码进行大量更改.
JPA提供程序是否有任何其他解决方案(最好是开源)可以"透明地"挂钩到后写缓存实现,最好是可以像Terracotta一样分发的解决方案?
我已经读过EclipseLink和Oracle Coherence可以实现这一点,但Coherence可悲的不是一个廉价的解决方案!
我试图从RSS源加载一些上下文,并在春天使用ehcache库将其作为缓存传递给客户端.这是我的代码:
import org.springframework.cache.annotation.Cacheable;
@Service
public class GlossaryReaderService {
@Cacheable(value = "glossaryList")
public List<Glossary> readGlossary(String url) {
XmlReader reader = null;
List<Glossary> extractedGlossay = new ArrayList<Glossary>();
SyndEntry entry;
SyndContent desc;
Glossary glossaryList = null;
try {
String decodedURL = URLDecoder.decode(url, "UTF-8");
reader = new XmlReader(new URL(decodedURL));
SyndFeed feed = new SyndFeedInput().build(reader);
for (Iterator i = feed.getEntries().iterator(); i.hasNext();) {
entry = (SyndEntry) i.next();
desc = entry.getDescription();
if (desc != null) { ...
extractedGlossay.add(glossaryList);
}
}
}
} catch (IOException | IllegalArgumentException | …
Run Code Online (Sandbox Code Playgroud) ehcache默认是支持多线程还是需要进行任何配置更改?在使用Ehcache的多线程我的应用程序时,我发现数据库命中数实际上在增加,即所有线程都没有可用的全局缓存,尽管我的缓存都是单例.有什么建议?
ehcache ×10
hibernate ×4
spring ×4
java ×3
caching ×1
dependencies ×1
jpa ×1
jpa-2.0 ×1
junit4 ×1
maven ×1
orm ×1
redis ×1
spring-4 ×1
spring-boot ×1
spring-cache ×1
spring-test ×1
terracotta ×1