I have to integrate spring and ehcache, and trying to implement it with blockingCache pattern
<ehcache:annotation-driven/>
there is one option for self-populating-cache-scope for shared (default) and method. could you please explain what is the difference?
There is also the annotation @Cacheable with selfPopulating flag
As per what I read on some post
http://groups.google.com/group/ehcache-spring-annotations/browse_thread/thread/7dbc71ce34f6ee19/b057610167dfb815?lnk=raot
it says when shared is used only one instance is created and the same is used everytime the same cache name is used so if I use the selfPopulating flag as true for one method,
all the threads trying to access other methods annotated with @Cacheable with selfPopulating flag set to true will go on hold which I dont want
<ehcache:annotation-driven/>
when self-populating-cache-scope = method on other hand creates separate instances for all methods annotated with @Cacheable with selfPopulating flag set to true so it doesn't create a problem.
But in this case when I try to remove a element using @TriggerRemove and giving the cache name used in @Cacheable will it search in each of those separate instances to find the value? Isnt this an overhead?
Answered by Eric on the ehcache google group above
In all cases there is one underlying Ehcache instance. What happens when you set selfPopulating=true is a SelfPopulatingCache wrapper is created.
If cache-scope=shared then all annotations using that named cache will use the same SelfPopulatingCache wrapper If cache-scope=method then one wrapper is created per method
Note in both cases the SelfPopulatingCache is a wrapper, there is still only one actual cache backing the wrapper(s)
As for blocking, If you read the docs for SelfPopulatingCache and BlockingCache you'll notice that ehcache does a compromise between cache level locking and per-key locking via key striping. http://ehcache.org/apidocs/net/sf/ehcache/constructs/blocking/BlockingCache.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With