ehcache « ehcache « Java Enterprise Q&A

Java Enterprise Q&A
39.Web Service
Java Enterprise Q&A » ehcache » ehcache 

1. Ehcache and Java

I am using ehCache to store larges amount of data. This cache is accessed about 3 times every second and must be kept up to date. I have a thread that runs which ...

2. Accessing same ehcache from 2 different war files

I have 2 different webapps (package into different war files) which needs to share some data via a cache (ehcache). I want to test out this idea with you to see ...

3. EHCache Disable/Shutdown

Is there a way to disable ehache externally using a property file? CacheManager.shutdown() doesnt seem to work? Actually we have 2 app with the same source code i require ehcache in one and ...

4. Cache integrity problem

I have an application that uses ehcache for cache (but I think this problem is framework-agnostic), with a method interceptor so basically if I mark my method for caching something like ...

5. When using ehcache, what synchronization do I need to do?

Let's say I start with a single CacheManager like this: private static CacheManager manager = CacheManager.create(); When I call getCache or addCache do I need to synchronize on the ...

6. ehcache LRU evicting recently used entries

Using Ehcache , after Java app works 2.5 days, I have this statistic

cacheHits:  31185262, approximate 131 per sec
cacheMisses:    4642979, approximate 19  per sec
evictedCount:  ...

7. ehcache update checker

12:18:55,541 INFO [UpdateChecker] New update(s) found: 2.0.0 [] How do I suppress ehcache checking for new update(s), this is happening while loading my j2ee application and when ehcache is getting initialized. ...

8. Ehcache midnight/nightly expiration strategy

It's not immediately obvious to me how to set EhCache to expire an entire cache nightly/at midnight. I can easily do this programmatically via a job of some sort, but ...

9. Coldfusion 8 and HTTP PUT - is there a way to PUT an object?

We are using EHCache with CF 8 to cache stuff on a central server using a RESTful interface over HTTP. I am trying to cache a cfquery object to the cache ...

10. atomic writes to ehcache

Context I am storing a java.util.List inside ehcache.

Key(String) --> List<UserDetail>
The ordered List contains a Top 10 ranking of my most active users. Problem Concurrent 3rd party clients might be requesting for this list. I have ...

11. How to differentiate between time to live and time to idle in ehcache

The docs on ehache says:

timeToIdleSeconds: Sets the time to idle for an element before it expires.
i.e. The maximum amount of time between accesses before an element expires

timeToLiveSeconds: Sets the time to ...

12. Sharing data between two instances in a load balanced java web application

I want to cache data in a java web application deployed on multiple instances. We are using spring 2.5.6. What is the easiest caching library to configure and use with spring? ...

13. Programatic cache creation

I switched from xml to programmatically cache creation and now I can't retrieve my cache by name. Here's a code snippet that shows what I'm doing maybe you can spot an obvious ...

14. Ehcache hangs in test

I am in the process of rewriting a bottle neck in the code of the project I am on, and in doing so I am creating a top level item that ...

15. Infinispan equivalent to ehcache's copyOnRead and copyOnWrite

I am planning to implement a cache solution into an existing web app. Nothing complicated: basically a concurrent map that supports overflowing to disk and automatic eviction. Clustering the cache could ...

16. EhCache default cache in java

I have this configuration for ehCache:


17. JCache with Oracle Coherence

Oracle Coherence states that it is "JCache-compliant". How can I take my code written against JSR-107, specifically the ehcache-jcache jar, and run it against Oracle Coherence? ...

18. How to cache rarely changed many-to-one entity in CF ORM?

How to cache rarely changed many-to-one entity in CF ORM, such as, userType where there are only < 10 types? I don't want the extra select to get the type ...

19. EHCache And Java Serialization Versioning Control

EHCache allows for persistance of the cache, and it requires all objects that are being cached to be Serializable. The objects that are being serialized and written to the Disk ...

20. When overFlowToDisk gets activated in EHCACHE?

I have some questions on "overflowToDisk" attribute of element? 1) I read at this URL that : overflowToDisk sets whether element can overflow to disk when the memory store has ...

21. ehcache memorystoresize and diskstoresize

[Avatar] 2010-09-23 18:20:41 IST I have the following configuration for my ehcache.

<CacheManager dynamicConfig="true" monitoring="autodetect" name="CacheManager1" 
  updateCheck="true"> <diskStore path="" /> <defaultCache 
  clearOnFlush="true" copyOnRead="false" copyOnWrite="false" diskAccessStripes="1" 
  diskExpiryThreadIntervalSeconds="5" diskPersistent="true" ...

22. Cache tags with Ehcache

I have 2 functions: first

public String doA(Integer userId, String someValue)
that I want to cache (taking into account parameters of function), and second
public String doB(Integer userId)
that should drops cache of function "doA" ...

23. ehcache cache "streams" of data

I want to cache the response to image requests. The images are the results of dynamic resizing of a larger image. I am using ehcache already for some caching. I would like ...

24. Is there a Faster way to Clear a Custom Cache Using the cacheGetSession Object?

I know I can use ColdFusion cache APIs to clear data as such:

<cfset cacheName = "custom">
<cfset ids = cacheGetAllIds(cacheName)>
<cfset cacheRemove(arrayToList(ids), false, cacheName)>
But in practice retrieving all the ids (i.e. cacheGetAllIds()) to ...

25. Ehcache - using a List as the cache value

So here is the problem I am trying to solve - I have an Object with two integer fields that I want to cache

public class MyObject {
   int x;

26. Does EHCache require put() in order for changes to instance to reflect (XA)?

I've started working with EHCache as a transactional cache (XAResource) in a JTA UserTransaction and I'm seeing something which is a bit strange, at least in my mind, and I'd like ...

27. Ehcache multiple JVM - opensource?

Hey I'm currently running ehcache with spring in tomcat. I have a couple webs servers running their own instance of ehcache which I want to now moved to a shared/distributed cache. ...

28. EhCache 1.4.1 and Monitoring

I am using one product which use ehcache 1.4.1 and I want to monitor the cache managed by that application. I saw that Terecotta released the EhCache monitor recently but it ...

29. Ehcache - using SelfPopulatingCache when data is not present

I am using the EhCache's decorator SelfPopulatingCache and have an issue when the cache tries to load a new entry, but it's non-existent (i.e. it doesn't exist in the database). ...

30. Sharing JGroups comm channel with EHCache

I'd like to use JGroups replication w/ EHCache and also share the communication channel with my own app. What's the recommended way to do this? (Similar to JBoss's "shared transport" feature) ...

31. How do I determine programmatically if ehcache is running?

I have a large java application that is configured to use JPA and Hibernate. It is also supposedly configured to use ehcaching for both entity and query caching. However, ...

32. How to implement Self Populating EHcache?

Could you please give me the steps to implement SelfPouplatingEhcache. Regards, Raju

33. How to get SelfPopulatingCache object reference

I able to create SelfpopulatinCache within the methodcacheinterceptor using aop.Now How to get SelfPopulatingCache object reference in my spring controller?.Thanks in Advance. Regards, Raj

34. Administration Of EhCahe

Is there any common JSP or page that can provide functionality to see the caches names, their size or contents or provide option to delete elements from cache or remove all ...

35. EhCache with JGroups usage in webapp

We are using EhCache with JGroups in our webapp for cache replication . But every time I hot deploy the webapp I find that net.sf.ehcache.distribution.jgroups.JGroupsCacheReplicator$ReplicationThread continues to run and holds references ...

36. How to use velocity + ehcache?

HI! I've searched the internet, and even the ehcache 200+ pages has a word velocity in it on 3 occasions. Well, my plan is to use annotations like @cahcable. As far as ...

37. How to renew or invalidate cache using SimpleCachingPageFilter in Ehcache?

we are using web-ehcache's net.sf.ehcache.constructs.web.filter.SimplePageCachingFilter, that configured by xml, to cache page where is JSON message, but this message can be changed by administrator. How to invalidate cache when administrator changes ...

38. Compare and Swap (CAS) implementation in EhCache

I am trying to find an equivalent of MemCache's CASMutator.cas in EhCache. Essentially, I am swapping out EhCache for MemCache and need to implement an interface that calls for setting ...

39. CacheManager.create() very slow

I am running an application using ehcache on an arm (arm5, no floating point unit) based machine, tested using both jamvm and openjdk and with a compact flash based rootfs (which ...

40. Ehcache - Asynchronous Cache Loading

I have a requirement to support refreshing of a cache in a background loader thread. The idea being that, the background loader periodically refreshes cached values without blocking threads wanting to ...

41. Cache vs HashMap for simple usecase

This must be a very basic:- Just curious, If I don't need distributed, cache-as-sor models, why do we need third party cache libraries (ehcache, memcached) when all you need (for simple ...

42. How to determine the optimal value to use for Ehcache's maxElements settings?

The currently released versions of Ehcache (2.4.1 is the latest) only support settings to control the maximum number of elements in the cache (maxElementsInMemory, and maxElementsOnDisk). How do you determine what ...

43. Ehcache or varnish or both?

should one use ehcache in favor of varnish? or the other way around? or both?

44. Cache invalidation in Ehcache

I am using Ehcache in Hibernate. How can i notify the cache that the database is changed. How can i invalidate the data is cached. How can i programatically acheive this? ...

45. hello world example for ehcache?

ehcache is a hugely configurable beast, and the examples are fairly complex, often involving many layers of interfaces. Has anyone come across the simplest example which just caches something like a single ...

46. Replicated Ehcache not working

I am trying to enable replecated ehcache and for some reason it does not seem to be working. My ehcache.xml -

    <?xml version="1.0" encoding="UTF-8"?> 

<ehcache xmlns:xsi=""

47. How to cache items which are returned by a list query? Using EHCache?

i am successfully able to cache results for queries that retrieve a single value.

@Cacheable(cacheName = "resourceCache")
public Resource find(int id) throws ResourceNotFoundException{
But for effiency reasons i need to implemented a method ...

48. jgroup members can't join?

I use a ehcache that distributes via jgroups. I use UDP multicat for the distribution. The ehcache lives within a webapp. There are several machines that run that webapp. For some reason ...

49. Multiple ehcache.xml in classpath

What will happen if there are multiple ehcache.xml files in the classpath? Which one will be picked up?

50. Ehcache -- Expiring on certain time

When using ehcache, is there a way to expire cache on certain time of the day? Thanks, Lawardy

51. ehcache help needed

Hello i am trying to setup Ehcache on my local system , There is only java based caching ,i am performing . I got the exception when i just ran the ...

52. ehcache help needed

I am trying to experiment with the overflowToOffHeap and maxMemoryOffHeap tags. I have configured this tag:

<cache name="sample-offheap-cache" maxElementsInMemory="1000" eternal="true" memoryStoreEvictionPolicy="LRU" overflowToOffHeap="true" maxMemoryOffHeap="256M"/> 
In my ehcache.xml also have the trial version licence ...

53. Does ehcache respect serialVersionUID?

We're running ehcache 1.5 in a cluster with RMI replication and update servers one by one (think of a load balancer/proxy on top and zero-downtime updates). We generally don't care about serialVersionUID. ...

54. Declarative (Annotation-based) Caching Solution for Java

Besides Spring 3.1 and ehcache-spring-annotations, do we have other alternatives that are other than EhCache and Spring?

55. Ehcache not storing anything in the file

I am trying to do a simple thing like store something in the cache and reterive it next time if it exists. For some reason everything works fine for the first ...

56. Ehcache help needed

I am using Ehcache 1.2.3 jar, in my Ehcache.xml i have configured maxElementsInMemory=100000,but the number of elements in memory always goes up till 50500, is there any default size mentioned in ...

57. What is a pull-through cache?

I found a reference to this concept in the EHCache documentation, but I could not find any proper explanation of what it means. It tried Googling around but to no ...

58. Java config equivalent of echcache.xml

Is there a sample Java Config for a standard ehcache XML config file (ehcache.xml) . I am using Spring 3.1.

59. ehcache SimpleCachingHeadersPageCachingFilter adding X-XSS-Protection & X-Content-Type-Options

I have SimpleCachingHeadersPageCachingFilter configured in my web.xml and it works fine but how would I go about adding some other stuff to the header like:

X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
I went to

60. How i can integrate Mybatis with ehcache?

How i can integrate Mybatis with ehcache? I have defined in my mapper the next:

<cache type="org.mybatis.caches.ehcache.EhcacheCache"/>
I put dependency mybatis-ehcache into pom.xml and i have created my ehcache.xml file But the console show me ...

61. How do I use ehcache to reload data?

I have a list of 100 items (Strings) that I want to put in ehcache. I will set them to expire after 1 hour. After that I want to read the ...

62. Web page caching using Ehcache

I am trying to make my web application faster by using caching of web pages for faster access next time so can anyone provide me guideline how to use Ehcache for ...

63. Filter url pattern conflict in web.xml ?

I am working on a projec, the application is in j2ee and I have used ehcache for web page caching but due to the entries of filter it gives me ...

64. How can I work around this apparent EhCache deadlock?

Using ehCache 2.4.4, I seem to have gotten into a deadlock on the ehCache Segment object. From other logging, I know that the 'waiting thread', 1694 last ran anything 9 ...

65. ehcache and logging issue

Some days ago I started using ehcache in web app. All was fine, and I do remember that when ehcache was putting something in the cach, or retrieving existing value from ...

66. Ehcache web CacheManager.replaceCacheWithDecoratedCache throws NPE

I have a very basic setup: Struts2 web-app, added to it Ehcache-Web and trying to make it work. Here's my ehcache.xml:

<ehcache xmlns:xsi=""

67. What is the "Ehcache" Forum Category for?

68. EhCache fundamendal Q

Hi, I'm newbie and I have few Q. I'm using Spring 2.5.6 & Ehcache 1.5 [list] How do I enable ehcache logging that prints ehcache DEBUG, INFO, WARN etc stmts Is there any FREE visual tool to monitor cache from Terracotta or others? I set timeToIdleSeconds=10 but after 10 sec I do not see my cache is getting invalidated. After 10 ...

69. Annotation Based Caching

70. Ehcache Monitor - No Probes

Caused by: org.hibernate.cache.CacheException: net.sf.ehcache.CacheException: Unable to load class org.terracotta.ehcachedx.monitor.probe.ProbePeerListenerFactory. Initial cause was org.terracotta.ehcachedx.monitor.probe.ProbePeerListenerFactory at net.sf.ehcache.hibernate.EhCacheRegionFactory.start( at org.hibernate.impl.SessionFactoryImpl.( at org.hibernate.cfg.Configuration.buildSessionFactory( at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory( at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory( ... 54 more Caused by: net.sf.ehcache.CacheException: Unable to load class org.terracotta.ehcachedx.monitor.probe.ProbePeerListenerFactory. Initial cause was org.terracotta.ehcachedx.monitor.probe.ProbePeerListenerFactory at net.sf.ehcache.util.ClassLoaderUtil.createNewInstance( at net.sf.ehcache.util.ClassLoaderUtil.createNewInstance( at net.sf.ehcache.config.ConfigurationHelper.createCachePeerListeners( at net.sf.ehcache.CacheManager.configure( at net.sf.ehcache.CacheManager.init( at net.sf.ehcache.CacheManager.( at net.sf.ehcache.hibernate.EhCacheRegionFactory.start( ... 58 more Caused by: java.lang.ClassNotFoundException: org.terracotta.ehcachedx.monitor.probe.ProbePeerListenerFactory at org.apache.catalina.loader.WebappClassLoader.loadClass( ...

71. ehcacheServer & cacheDecoratorFactory

Is it possible to use cacheDecoratorFactory with ehcacheServer with REST API. I realized current distribution comes with ehcache-core-2.0.1. This does not let server to accept the configuration ( ehcache.xml) with cacheDecoratorFactory. If we chance it with ehcache-core-2.4.x things start to move. However I could not use the cache as it still gives 404. Any ideas will be highly appreciated. rn

73. IllegalAccessError for CachManager

Thanks for your reply. I am not quite sure what you mean when you say "Please use jars of the same version." The maven pom file for hibernate specifies ehcache 1.1, and that is the only version that we have in the project. As an aside, we are successfully using ehcache in the project already to cache domain objects. I am ...

74. Self-Refreshing Cache

So what's the best way to get a cache to self-refresh. Essentially, I have a cache of stats information for graphs to display. What I want is for the graphs to always be able to get the data (even if it's stale) but when a request for the cache comes in and gets back stale data, i want to either have ...

75. Getting monitor to work

Hi there! I've decided to move from terracotta to plain ehcache for a while, after 2 days of pain trying to get terracotta to work in our environment. Since we do require some monitoring, I'm trying to get the ehcache monitor to work. I've downloaded it and when I run the startup I get some exception on connect timeout. So I'm ...

76. value of multicastGroupAddress

Hi, I'm using caches with replication and it works fine so far. But I'm now in the situatuation that more than one application within the same network are using EhCache. As far as I can see it is enough to change the IP address value of multicastGroupAddress to something else for every application. Does the value matter in any way or ...

77. list remote cache names

Eugene, You know your data the best and you set where it is stored based on your ehcache.xml. To get the details of the information stored in TSA, you _need_ the ehcache.xml of all the clients connecting to the TSA. You need to know the cacheManager and cacheNames and invoke it from a L1 client as "rajoshi" also mentioned. What "rajoshi" ...

79. Custom SizeOf

Hi, Is there some way to provide a custom implementation for the SizeOf class. Most our objects know their own sizes and it would increase performance a lot to avoid the graph walking. We currently get this message: ObjectGraphWalker.checkMaxDepth():209| The configured limit of 1,000 object references was reached while attempting to calculate the size of the object graph. Severe performance degradation ...

80. Garbage collection on L2 effecting Garbage collection on L1

Hi, after a few days of running our app with Terracotta , the system slowed to a crawl and the client logs showed the following: ********************************************************************** 2011-11-27 20:28:08,101 [TC Memory Monitor] WARN - Detected long GC>8,000ms. GC count:1. GC Time:9,581ms. Frequent long GC cycles cause severe performance degradation. 2011-11-27 20:28:36,632 [TC Memory Monitor] WARN - Detected long GC>8,000ms. GC ...

81. EhCache 2.5 & Coldfusion

No worries. Scenario: Doing saturation testing using EhCache 2.6, Terracotta 3.6, bigMemory. Testing what we call "form" objects - these are large object graphs that represent the configuration for html forms. 100kb - 2mb+ each graph. They are expensive to create. This test consists of 2 threads. Throughput of tests is in the order of 50 req/minute during "normal" operation and ...

82. CacheException : Exception while starting webapp.

Hello All, I am new user of Ehcache . I am trying to use ehcache in my application. I have written CacheManager cacheManager = CacheManager.getInstance(); in init method of my servlet. While loading the servlet I am seeing exception in logs. Its net.sf.ehcache.CacheException: Unable to load class net.sf.ehcache.terracotta.StandaloneTerracottaClusteredInstanceFactory. Initial cause was net.sf.ehcache.terracotta.StandaloneTerracottaClusteredInstanceFactory.(net.sf.ehcache.config.TerracottaClientConfiguration) at net.sf.ehcache.util.ClassLoaderUtil.createNewInstance( at net.sf.ehcache.terracotta.TerracottaClusteredInstanceHelper.newClusteredInstanceFactory( at net.sf.ehcache.terracotta.TerracottaClient.createNewClusteredInstanceFactory( at net.sf.ehcache.terracotta.TerracottaClient.createClusteredInstanceFactory( at ...

83. sizeOf and ColdFusion

Hey All, Testing 2.5 with ColdFusion & I believe the sizeOF implementation in EhCache is not correct. If I cache.put() on a single ColdFusion object that contains 1 method and one private property, I get the following warning message: "The configured limit of 1,000 object references was reached while attempting to calculate the size of the object graph" I suspect that ...

84. if heartbeat between t1 and t2 is very long...can it cause queries to cache to take very long time

Hi : here are two scenarios Im considering. 1.if the timeout settings betwenn t1 and t2 are high (hours) and t1 does a full garbage connection ( using CMS ) , will the tsa (t2) halt all other t1s that are requesting items from the cache untill the garbage collection has occured. 2. if non-stop caches are used and t1 is ...

85. How to size caches in ehcache 2.5

I just upgraded to ehcache 2.5 and now apparently I have to set a maxBytesLocalHeap value on the cache manager. However, I want the value to be the maximum possible one, not set a particular one. we have hundreds of instances that would need reconfiguration otherwise. How can I tell ehcache to just use as much of the heap as it ...

86. How PUT method in ehcache.xml

87. ehcache-standalone-server is frozen?

88. maxBytesLocalHeap and defaultCache

89. Can somebody explain behaviour of isKeyInCache

public class TestEhCache { @Test public void test() { CacheManager mCacheManager = CacheManager.getInstance(); TransactionController mTransactionManager = mCacheManager.getTransactionController(); System.out.println("With all in one transaction ------------"); mTransactionManager.begin(); mCacheManager.addCache("TestCache1"); Ehcache cache1 = mCacheManager.getEhcache("TestCache1"); System.out.println("Before put:"); System.out.println("Keys = " + new ArrayList(cache1.getKeys())); System.out.println("isKeyInCache = " + cache1.isKeyInCache(Long.valueOf(1))); cache1.put(new Element(Long.valueOf(1), Long.valueOf(1))); System.out.println("After put:"); System.out.println("Keys = " + new ArrayList(cache1.getKeys())); System.out.println("isKeyInCache = " + cache1.isKeyInCache(Long.valueOf(1))); cache1.remove(Long.valueOf(1)); System.out.println("After remove:"); ...

90. SimplePageFragmentCachingFilter documentation

Hi, I'm trying to understand how to implement the SimplePageFragmentCachingFilter. I'm using Spring and Freemarker. As I understand a page fragment filter, you identify fragments of a page you want to cache, specify a key and the page fragment cache stores these elements. When it comes to the SimplePageFragmentCachingFilter: 1. How do you specify a page fragment? 2. Can you manually ...

91. When Terracota not reachable, what config I can set make it stop to retry

What you are looking for is probably a timeout/retry feature for cacheManager which limits the no of times it connects to TSA when its not reachable. While we do not have this feature currently, I think your request is perfectly reasonable. Can you put in a new feature request JIRA in our community forums so that our Eng team can evaluate ...

92. Remote caching using ehcache

We have a classic problem of multiple processes subscribing to same dataset from database. To solve this we are planning to implement a caching mechanism using ehcache. The solution would have a server component that maintains the cache and the client component that uses the cache. Hence it would be quite useful if you have any references to examples on how ...

93. ehcache problem

Hi we are using ehcache in our project and we have two environments in one server ( developement and QA) the ehcache disk store is set to different values for both environments but when I try to restart the server for QA for example, it doesn't start successfully; throwing an exception like: The Disk store is not active. I think the ...

94. Caching with Ehcache  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.