[Logo] Terracotta Discussion Forums
  [Search] Search   [Recent Topics] Recent Topics   [Members]  Member Listing   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
[Expert]
Sometimes getting NULL returned when calling get(key) on Cache  XML
Forum Index -> Ehcache
Author Message
amittare

neo

Joined: 05/02/2011 23:03:48
Messages: 4
Offline

I am using ehcache 1.1 jar in my application. I am having singleton instance of cache object which is used to put and get elements. I am not sure how to distinguish it as standalone or distributed, so if you can just ask me questions on this so that it gets clarified to you in order to understand and solve my problem.

My problem is the get(key) works most of the times, but at times it returns null from the cache for the key actually existing in the cache.
klalithr

consul

Joined: 01/23/2011 10:58:07
Messages: 466
Offline

I recommend that you start with the ehcache documentation and try the samples found here...

http://ehcache.org/documentation/samples.html

Karthik Lalithraj (Terracotta)
ari

seraphim

Joined: 05/24/2006 14:23:21
Messages: 1665
Location: San Francisco, CA
Offline

How are you even finding ehcache 1.1? It really isn't available to download anywhere, is it?

--Ari
[WWW]
amittare

neo

Joined: 05/02/2011 23:03:48
Messages: 4
Offline

Actually my application is 6 years old, and that is the ehcache version my application is using right from start I guess. I am looking after enhancements of the application.

Also the ehcache is used as standalone.

Please let me know any remedy for my problem.
klalithr

consul

Joined: 01/23/2011 10:58:07
Messages: 466
Offline

Firstly - I would recommend that you move to the most recent version of Ehcache. This could very well solve your issue. Please try this as step 1.

Secondly, Get could also return null if the element has expired due to TTI and TTL settings in the cache. I need more information about your use case to accurately help you out. Please share your ehcache.xml, the code that you use to get the element (3-4 lines around it would suffice - are you using iskeyincache) , and how you determine that element is present in the cache?

Karthik Lalithraj (Terracotta)
amittare

neo

Joined: 05/02/2011 23:03:48
Messages: 4
Offline

1) My ehcache.xml :
<ehcache>
<diskStore path="java.io.tmpdir" />

<defaultCache
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="300"
timeToLiveSeconds="600"
overflowToDisk="false"
/>

<cache name="bamEntryCache"
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="3600"
timeToLiveSeconds="3600"
overflowToDisk="false"
/>

<cache name="globalUidCache"
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="86400"
timeToLiveSeconds="86400"
overflowToDisk="false"
/>

<cache name="serverTabCache"
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="86400"
timeToLiveSeconds="86400"
overflowToDisk="false"
/>


</ehcache>

2) The code is not using iskeyincache().

3) Code used to get the element :
try {
Element element = cache.get((Serializable) key);

if (element != null) {
result = element.getValue();
} else {
result = null;
}

} catch (IllegalStateException e) {
log.warn(e, e);
} catch (CacheException e) {
log.warn(e, e);
}
klalithr

consul

Joined: 01/23/2011 10:58:07
Messages: 466
Offline

Did you move to the most recent version of Ehcache? 1.1 is very old.

Based on your TTI/TTL settings, you have those set to 1 hour for bamEntryCache and 1 day for globalUIdCache. Also MaxElementsInMemory is set to 10000. Anything outside these boundaries would result in a cache miss - this is expected behavior. For more information on how these work I would suggest looking at the documentation in ehcache website

http://ehcache.org/documentation/configuration.html

Karthik Lalithraj (Terracotta)
amittare

neo

Joined: 05/02/2011 23:03:48
Messages: 4
Offline

No, I haven't moved to recent version yet.

When we say MaxElementsInMemory, is it the number of elements we put in cache by invoking cache.put(new Element(key,value)) ?

Will you please clarify on this for me ?
rajoshi

seraphim

Joined: 07/04/2011 04:36:10
Messages: 1465
Offline

Issue seems to be resolved.Please let us know if more information is required.

Rakesh Joshi
Terracotta.
 
Forum Index -> Ehcache
Go to:   
Powered by JForum 2.1.7 © JForum Team