• Bug
  • Status: Closed
  • 2 Major
  • Resolution: Fixed
  • ehcache-core
  • cdennis
  • Reporter: dam6923
  • December 29, 2010
  • 0
  • Watchers: 1
  • July 27, 2012
  • April 22, 2011

Description

Would it be possible to change the putFromLoad method of classes implementing EntityRegionAccessStrategy?

I suggest the use of region.contains(key) in (see: ReadOnlyEhcacheEntityRegionAccessStrategy) instead of region.get(key) != null.

The problem is that I use a decorator for my cache and I pre-populate the cache with all the data from the database on startup. The decorator returns a dummy object for any calls to get(key) that are not represented in the cache (returns a null value), so that Hibernate does not make a call to the database to find only that the row doesn’t exist. This also saves me a lot of RAM because there are many, many, keys for which there are no associated rows. For each missing row, a key is inserted into the cache.

The problem is that, when the putFromLoad method is invoked, it calls get(key), and my decorator returns the dummy Element so nothing ever gets put in the cache. If it were to call contains(key), I believe it would not hit the decorator#get(key) method and would correctly see that there is no value in there, and a real value, from the database, gets put into the cache in putFromLoad.

Comments

Chris Dennis 2011-01-03

The immediate thing that springs to mind about this is that {{Region.contains(Object key)}} as it is currently implemented in Ehcache does not check for element expiry. This would mean that users who configure read-only Hibernate caches with TTI/TTL based invalidation might see increased DB traffic since the initial putFromLoad will not propagate the cache, a subsequent cache miss, and db load would be required. Not that rules this out at all… I’ll just need to think about it in some more detail first.

Chris Dennis 2011-04-22

Talked with Alex Snaps about this and we’re in agreement that the benefit of not having to resolve the value here more than outweighs any potential negative effects.