Any way to use BlockingCache?

688 views
Skip to first unread message

mekondelta

unread,
Mar 21, 2011, 11:33:08 AM3/21/11
to Ehcache Spring Annotations
I have the annotations working nicely but am now working on a project
which has quite a high load and I'm worried about spikes in requests
where a cache miss will cause many hits to the SOR until one of the
requests finally populates the cache.

Is this possible with the annotations?

Eric Dalquist

unread,
Mar 21, 2011, 11:43:48 AM3/21/11
to ehcache-sprin...@googlegroups.com
I think you want to use the selfPopulating attribute on @Cacheable

http://code.google.com/p/ehcache-spring-annotations/wiki/UsingCacheable

With that set to true the annotations use Ehcache's self-populating cache support to ensure on a miss only one thread will end up making it into the annotated method and all other concurrent requests will block until the creating request completes and populates the cache.

-Eric

mekondelta

unread,
Mar 21, 2011, 11:56:54 AM3/21/11
to Ehcache Spring Annotations
Thank you! I will try this out....

On Mar 21, 3:43 pm, Eric Dalquist <eric.dalqu...@gmail.com> wrote:
> I think you want to use the selfPopulating attribute on @Cacheable
>
> http://code.google.com/p/ehcache-spring-annotations/wiki/UsingCacheable
>
> With that set to true the annotations use Ehcache's self-populating cache
> support to ensure on a miss only one thread will end up making it into the
> annotated method and all other concurrent requests will block until the
> creating request completes and populates the cache.
>
> -Eric
>

mekondelta

unread,
Apr 6, 2011, 11:14:00 AM4/6/11
to Ehcache Spring Annotations
Thank you, I've managed to get the selfPopulating function working.

Can you tell me what happens if there is an error on the thread that
is calling the annotated method? Do all the calls that are waiting for
this thread all fail also?

Couldn't see anywhere in the documentation where this use case is
mentioned.

Best Regards, Chris.

Eric Dalquist

unread,
Apr 6, 2011, 11:50:57 AM4/6/11
to ehcache-sprin...@googlegroups.com
Depends on how you have @Cacheable setup, I have two examples below of the two possible configs.


In this example if you have 10 threads all call getFoo at the same time and a service that getFoo interacts with is causing an exception to be thrown. Each thread, one by one, will proceed into getFoo and have the exception thrown.

@Cacheable(cacheName="data", selfPopulating=true)
public Foo getFoo(long id);


In this example if you have 10 threads all call getFoo at the same time and a service that getFoo interacts with is causing an exception to be throw. Only the first thread will call getFoo and when the exception is thrown the Exception object will be stored in the "exception" cache and each subsequent call to getFoo will re-throw that same exception object until it expires from the "exception" cache.

@Cacheable(cacheName="data", selfPopulating=true, exceptionCacheName="exception")
public Foo getFoo(long id);


In general the way I've used selfPopulating is to always define an exception cache so that when a problem occurs we don't beat on the broken service too much. Generally the exception cache TTL to a fairly low number so the service is retried regularly but even with a 30 second TTL that can save a lot of extra invocations.

mekondelta

unread,
Apr 7, 2011, 9:17:26 AM4/7/11
to Ehcache Spring Annotations
Thanks Eric, very helpful as ever!

Swaranga Sarma

unread,
Feb 13, 2013, 2:33:26 PM2/13/13
to ehcache-sprin...@googlegroups.com
Hi Eric,

It seems that the selfPopulating property is deprecated. Why is that? And what are its alternatives?

Thanks,
Swaranga

Eric Dalquist

unread,
Feb 17, 2013, 9:01:13 AM2/17/13
to ehcache-sprin...@googlegroups.com
If you read the JavaDoc for the property: http://ehcache-spring-annotations.googlecode.com/svn/site/current/apidocs/index.html

It tells you what to use instead.

--
You received this message because you are subscribed to the Google Groups "Ehcache Spring Annotations" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ehcache-spring-anno...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages