So the self-populating feature is mostly just using the
SelfPopulatingCache construct that Ehcache provides. What the annotations library does is have some special support for automatically creating a CacheEntryFactory that essentially wraps the annotated method and passes along the original arguments to the method (a ThreadLocal is used for this) to get the value the CacheEntryFactory returns.
As you describe the biggest benefit to this is that there will only ever be one call made to the method for a key until the entry expires. I often use it for shared resources that take a long time to return, for example a DAO that gets weather data from a remote feed. In that example there is no point to have N concurrent users all making the same 8 second HTTP request on a miss, it is better to have 1 thread make the request and the other N-1 threads just wait and use the data retrieved by the first thread.
As for scope, the SelfPopulatingCache class is a decorator that wraps an Ehcache instance. If you set the scope to shared (the default) all @Cacheable annotations that refer to cache X with selfPopulating set to true will use the same SelfPopulatingCache instance which means they all share the same locks and only one of the methods can be invoked at a time. If you set the scope to method a SelfPopulatingCache instance is created for each method so the locking is scoped to each method. I hope that helps, if not I can see about providing some pseudo-code examples.
We did add a refreshing construct in trunk. Take a look at the refreshInterval on the @Cacheable annotation in the javadocs below. You also need to specify the scheduler and executor attributes on the <ehcache:annotation-driven> element which are used to do the background processing to refresh cached elements.
https://ehcache-spring-annotations.ci.cloudbees.com/job/ehcache-spring-annotations_trunk-site/ws/core/target/site/apidocs/index.html
http://code.google.com/p/ehcache-spring-annotations/source/browse/trunk/core/src/main/resources/com/googlecode/ehcache/annotations/ehcache-spring-1.2.xsd
I'm still not wholly comfortable with the feature. The entire Object[] of arguments is stored in the cache element meaning you need to be very careful of the following:
-That your key arguments are immutable (if they are changed by reference the key is never recomputed and your cached value essentially gets "lost" in the cache)
-That your key arguments are not going to cause memory issues by sticking around "forever", where forever is the duration of the cache timeout.
-That there is NO Thread specific context data used by the annotated method or any method that it calls. Things like the Thread ContextClassLoader and ThreadLocals cannot be copied by the annotations library and made available in the refresh thread so they either will have no value or the incorrect value.