标签: ehcache

EhCache在java中默认缓存

我有ehCache的配置:

<ehcache>
    <defaultCache
            name="defaut"
            maxElementsInMemory="5"
            eternal="false"
            timeToIdleSeconds="20"
            timeToLiveSeconds="20"
            overflowToDisk="false"
            diskPersistent="false"
            memoryStoreEvictionPolicy="LRU"
            />           
</ehcache>
Run Code Online (Sandbox Code Playgroud)

如何访问EhCache的默认缓存?

CacheManager.getInstance().getCache("default"); // returns null
Run Code Online (Sandbox Code Playgroud)

java ehcache

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

Hibernate EHCache vs MemCache

我想在我的Web应用程序中使用缓存,该缓存和分发也是如此.

我在小型Web应用程序中分别使用了EHCache和MemCache.

谷歌搜索并得到关于两者的混合评论,因此希望得到一些帮助和强大的功能,所以我可以决定哪个框架适合我的Web应用程序.

如果需要进一步的细节,请告诉我.

谢谢 !!

memcached ehcache spymemcached

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

ehcache和ehcache-core之间的区别

我是Spring框架中的ehcache v/s ehcache-core的初学者,我的pom.xml使用的是ehcache 1.5.0版本

<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>1.5.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

现在,它需要更新ehcache版本,因为它将在另一个jar中使用: - 更新了ehcache版本2.7.0但它返回错误net.sf.ehcache.Cache.getStatistics()方法未找到.

现在,我将通过ehcache-core 2.5.7替换ehcache: -

<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache-core</artifactId>
<version>2.5.7</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

它是否打破了其他功能或与ehcache一样工作?

java ehcache pom.xml difference

14
推荐指数
1
解决办法
6163
查看次数

无法将名称[org.hibernate.cache.ehcache.EhCacheRegionFactory]解析为策略[org.hibernate.cache.spi.RegionFactory]

我试图升级我的Spring和Hibernate版本.我正在使用hibernate 3,现在我已升级到hibernate 4.3.6.升级后,我在ehcache实现中遇到了一个奇怪的问题.

当我升级到hibernate 4时,我添加了一个条目:

<prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory </prop>
Run Code Online (Sandbox Code Playgroud)

现在我得到的例外是:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/config/persistence.xml]: Invocation of init method failed; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.cache.spi.RegionFactory]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1566)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1127)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1051)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:949)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:603)
    ... 124 more
Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.cache.spi.RegionFactory]
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:261)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:225)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206)
    at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:295) …
Run Code Online (Sandbox Code Playgroud)

caching hibernate ehcache

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

寻找java.util.Map的替代品

问题

关注这个问题,似乎基于文件或磁盘的Map实现可能是我在那里提到的问题的正确解决方案.精简版:

  • 现在,我已经Map实现了一个ConcurrentHashMap.
  • 条目以相当固定的速率不断添加到其中.稍后详情.
  • 最终,无论如何,这意味着JVM耗尽了堆空间.

在工作中,(强烈)建议我使用SQLite解决这个问题,但在询问上一个问题之后,我认为数据库不是这项工作的正确工具.所以 - 让我知道这听起来有多疯狂 - 我认为更好的解决方案是Map存储在磁盘上.

不好的主意:自己实现这个.更好的主意:使用别人的图书馆!哪一个?

要求

必备:

  • 自由.
  • 持久性.数据需要在JVM重启之间保持不变.
  • 某种可搜索性.是的,我需要能够检索这些数据以及将其丢弃.基本结果集过滤是一个加号.
  • 与平台无关.需要在Windows或Linux计算机上进行生产部署.
  • 可以清除.磁盘空间是有限的,就像堆空间一样.我需要摆脱n几天前的条目.如果我必须手动执行此操作,这不是什么大问题.

尼斯对富人:

  • 使用方便.如果我能在本周末完成这项工作,那就太好了.
    更好的是:一天结束.这将是非常,非常巨大的,如果我能一个JAR添加到我的类路径,改new ConcurrentHashMap<Foo, Bar>();new SomeDiskStoredMap<Foo, Bar>();
    和完成.
  • 体面的可扩展性和性能.最坏的情况:新的条目(平均)每秒增加3次,每秒,每天,每天.但是,插入并不总是顺利发生.可能就是(no inserts for an hour)这样(insert 10,000 objects at once).

可能的解决方案

java caching hadoop berkeley-db ehcache

13
推荐指数
2
解决办法
3281
查看次数

ehcache统计信息不正确:命中+未命中== 0

我有一个问题,net.sf.ehcache.CacheManager出现返回无效的统计信息.

我正在使用ehcache-core v2.3.2(最新版本)ehcache-spring-annotations.

问题是,getMemoryStoreObjectCount返回1个对象同时兼具getCacheHitsgetCacheMisses返回0.应该是总计数hits + misses吗?

下面的单元测试应该说明问题(它应用于数据库):

@Test
public void testCache() {
    Entity e = ..
    dao.storeEntity(e);
    dao.getEntity(e);
    assertEquals(1, cache.getStatistics().getMemoryStoreObjectCount()); // ok
    assertEquals(0, cache.getStatistics().getCacheHits()); // ok
    assertEquals(1, cache.getStatistics().getCacheMisses()); // fails due to 0

}
Run Code Online (Sandbox Code Playgroud)

为了完整性,我包括所有必要的配置:

Spring配置

<ehcache:annotation-driven cache-manager="ehCacheManager" />
<bean id="ehCacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
    <property name="configLocation" value="classpath:ehcache.xml"/>
</bean>
Run Code Online (Sandbox Code Playgroud)

ehcache.xml中

<ehcache>
     <defaultCache eternal="false" maxElementsInMemory="1000"
        overflowToDisk="false" diskPersistent="false" timeToIdleSeconds="0"
        timeToLiveSeconds="600" memoryStoreEvictionPolicy="LRU"/>
</ehcache>
Run Code Online (Sandbox Code Playgroud)

@Cacheable(keyGenerator=@KeyGenerator(name="StringCacheKeyGenerator")) …
Run Code Online (Sandbox Code Playgroud)

java spring annotations hibernate ehcache

13
推荐指数
3
解决办法
6400
查看次数

EHCache与Terracotta Vs Infinispan

我们正在新项目的设计阶段工作,我们需要决定缓存框架.我们需要决定是否将EHCache与Terracotta或Infinispan一起用于缓存要求?任何人都可以向我提供EHCache和Infinispan的优缺点吗?

提前致谢.

terracotta ehcache infinispan

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

我应该如何在ehCache中使用@CachePut和@CacheEvict注释(ehCache 2.4.4,Spring 3.1.1)

我尝试了一些新的Spring功能,我发现@CachePut和@CacheEvict注释没有任何效果.可能是我做错了什么.你可以帮帮我吗?

我的applicationContext.xml.

<cache:annotation-driven />

<!--also tried this-->
<!--<ehcache:annotation-driven />-->

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

这部分效果很好.

@Cacheable(value = "finders")
public Finder getFinder(String code)
{
    return getFinderFromDB(code);
}

@CacheEvict(value = "finders", allEntries = true)
public void clearCache()
{
}
Run Code Online (Sandbox Code Playgroud)

但是,如果我想从缓存中删除单个值或覆盖它,我不能这样做.我测试了什么:

@CacheEvict(value = "finders", key = "#finder.code")
public boolean updateFinder(Finder finder, boolean nullValuesAllowed)
{
    // ...
}

/////////////

@CacheEvict(value = "finders")
public void clearCache(String code)
{
}

/////////////

@CachePut(value = "finders", key = "#finder.code")
public Finder updateFinder(Finder finder, boolean nullValuesAllowed) …
Run Code Online (Sandbox Code Playgroud)

spring ehcache

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

Spring MVC的ehcache或spring cache中最好的Cache实践是什么?

计划在基于Spring网络的应用程序中实现静态数据的缓存机制,任何人都可以解释哪个是最好的以及它是如何工作的?

  • 的Ehcache
  • Spring Cache

java spring spring-mvc ehcache spring-cache

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

使用带有Spring Annotations的ehcache 3(不使用Spring Boot)

我试图让Ehcache 3在不使用Spring引导的情况下使用Spring 4.

这是一个使用Spring Boot的工作示例,但我正在处理一个不使用Spring Boot的现有应用程序.

问题是spring-context-support(添加Spring的缓存注释)要求Ehcache的CacheManager在这个类路径上:net.sf.ehcache.CacheManager

但是,在Ehcache 3中,CacheManager类驻留在另一个类路径上:org.ehcache.CacheManager.

所以,基本上spring-context-support不支持Ehcache 3.你必须直接使用JSR-107注释,而不是Spring提供的注释.

但显然它适用于Spring Boot.也许有一种方法可以使它与标准的Spring应用程序一起工作.这就是我所希望的.我真的想要使用Spring自己的注释而不是JSR-107注释.

spring ehcache spring-boot spring-4 jsr107

13
推荐指数
1
解决办法
8046
查看次数