I have a few functions in my code where it makes much sense (seems even mandatory) to use memoization.
I don't want to implement that manually for every function separately. Is there some way (for example like in Python) I can just use an annotation or do something else so I get this automatically on those functions where I want it?
解决方案
Spring 3.1 now provides a @Cacheable annotation, which does exactly this.
As the name implies, @Cacheable is used to demarcate methods that are cacheable - that is, methods for whom the result is stored into the cache so on subsequent invocations (with the same arguments), the value in the cache is returned without having to actually execute the method.