I am interested in using Spring's Cache Abstraction on a module that I am working with but all data operations are on collections to avoid multiple datasource invocations, so I am not sure I have a decent "pointcut" at which to method-level cache. This is not a Spring or Java specific issue but more of a design problem.
For example:
public class SomeDataAccessObject{
private SomeBatchingDataSourceAbstraction datasource;
//would ideally add a cache annotation to this method to cache based on input, but that
//clearly won't work in this scenario because we are loading multiple which may have
//some cache hits only
public List<String> getNames(List<Integer> ids){
//ideally I would load as many names as I can from the cache and
//then use the datasource to get the rest
//I can achieve this with a programatic cache but it is very invasive
return datasource.fetch(ids);
}
}
Has anyone come up with a good way to redesign such a scenario that would allow me to use Spring-style method level declarative caching? Please remember that I want to keep the data access object (above) effectively stateless in order to be thread safe.