关注这个问题,似乎基于文件或磁盘的Map实现可能是我在那里提到的问题的正确解决方案.精简版:
Map实现了一个ConcurrentHashMap.在工作中,(强烈)建议我使用SQLite解决这个问题,但在询问上一个问题之后,我认为数据库不是这项工作的正确工具.所以 - 让我知道这听起来有多疯狂 - 我认为更好的解决方案是Map存储在磁盘上.
不好的主意:自己实现这个.更好的主意:使用别人的图书馆!哪一个?
n几天前的条目.如果我必须手动执行此操作,这不是什么大问题.new ConcurrentHashMap<Foo, Bar>();到new SomeDiskStoredMap<Foo, Bar>();(no inserts for an hour)这样(insert 10,000 objects at once).我有一个问题,net.sf.ehcache.CacheManager出现返回无效的统计信息.
我正在使用ehcache-core v2.3.2(最新版本)ehcache-spring-annotations.
问题是,getMemoryStoreObjectCount返回1个对象同时兼具getCacheHits和getCacheMisses返回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) 我们正在新项目的设计阶段工作,我们需要决定缓存框架.我们需要决定是否将EHCache与Terracotta或Infinispan一起用于缓存要求?任何人都可以向我提供EHCache和Infinispan的优缺点吗?
提前致谢.
计划在基于Spring网络的应用程序中实现静态数据的缓存机制,任何人都可以解释哪个是最好的以及它是如何工作的?
我试图让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注释.
我正在寻找一个简单的内存(和进程中)缓存,用于查询数据的短期缓存(但短期意义超出请求/响应,即会话边界).EhCache可能会工作,但看起来好像它可能不提供我需要的东西:限制不是缓存的对象数量,而是(大致)限制缓存数据消耗的内存量.
我知道很难在没有序列化的情况下找出给定对象的确切内存使用情况(我想避免在一般情况下因为它的速度慢而无法实现我的用途),而且我自己也不得不提供大小估计.
那么:是否有一个简单的开源java缓存,允许定义缓存对象的"权重",以限制缓存的事物数量?
编辑(2010年11月):对于它的价值,有一个名为Java CacheMate的新项目试图解决这个问题,以及其他一些改进的想法(多级内存中进程缓存)
应用程序启动时我收到了以下警告.
2009-05-13 09:19:41,171 WARN net.sf.ehcache.config.Configurator - No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath:jar:file:/app/java/lib/ehcache-1.1.jar!/ehcache-failsafe.xml
Run Code Online (Sandbox Code Playgroud)
我在以下url中找到了encache代码.ConfigurationFactory Code
应用程序正在尝试加载ehcache.xml但无法找到该文件,因此它加载了ehcache-failsafe.xml.我想知道这是否会导致应用程序出现任何问题?什么是影响加载ehcache-failsafe.xml?
我正在使用Spring/Hibernate/Tomcat和mysql数据库构建Route Planner Webapp,我有一个包含只读数据的数据库,例如总线停止坐标,从不更新的总线时间.我正在尝试让应用程序运行得更快,每次运行应用程序时,它都会对数据库执行大约1000次读取以计算路径.
我已经设置了一个Ehcache,它大大提高了从数据库时间的读取.我现在正在设置terracotta + Ehcache分布式缓存以与多个Tomcat JVM共享缓存.这看起来有点复杂.我已经尝试过memcached,但它的表现并不像ehcache那么快.
我想知道MongoDb或Redis是否更适合.我没有使用nosql的经验,但如果有人有任何想法,我将不胜感激.我需要的是快速访问只读数据库.
在我的Spring + Hibernate项目中,我使用LogBack通过SLF4J 1.6.4进行日志记录.现在,我添加了Ehcache 2.2.0(通过ehcache-spring-annotations-1.1.3).缓存似乎是作为方法工作,使用@Cacheable注释,不再执行,但返回正确的结果.但是,我有兴趣看到Ehcache写的日志.由于Ehcache也使用SLF4J,我想,日志应该写入我的日志文件中.但是,这种情况并没有发生.logback.xml具有以下内容.
<root level="info">
<appender-ref ref="STDOUT"/>
<appender-ref ref="ROLLING"/>
</root>
Run Code Online (Sandbox Code Playgroud)
添加以下内容也无济于事
<logger name="net.sf.ehcache">
</logger>
Run Code Online (Sandbox Code Playgroud)
ehcache.xml中
<cache name="sampleCache1"
eternal="false"
overflowToDisk="true"
timeToIdleSeconds="300"
timeToLiveSeconds="600"
memoryStoreEvictionPolicy="LFU"
/>
Run Code Online (Sandbox Code Playgroud)
请告诉我克服这个问题.
Ehcache正在使用SLF4J 1.6.1,而我的项目正在使用SLF4J 1.6.4.它会引起任何问题吗?
谢谢
我正在尝试ehcache为我的应用程序实现但是当尝试调用服务器时,收到以下错误 -
java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: WebApplicationContext for namespace 'dispatcher-servlet': startup date [Thu Apr 16 14:37:53 IST 2015]; root of context hierarchy
at org.springframework.context.support.AbstractApplicationContext.getApplicationEventMulticaster(AbstractApplicationContext.java:344)
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:331)
at org.springframework.web.servlet.FrameworkServlet.publishRequestHandledEvent(FrameworkServlet.java:1061)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:996)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
at …Run Code Online (Sandbox Code Playgroud) ehcache ×10
spring ×5
hibernate ×4
java ×4
caching ×2
spring-boot ×2
spring-mvc ×2
annotations ×1
berkeley-db ×1
hadoop ×1
infinispan ×1
jsr107 ×1
logback ×1
mysql ×1
neo4j ×1
nosql ×1
slf4j ×1
spring-4 ×1
spring-cache ×1
terracotta ×1