cache-annotations provides an easy way to cache method results by adding an annotation:
@Cached
public AnObject anExpensiveLoadMethod(String name, int someParam){
...
load();
...
return it;
}
...
// load operation will be called, result will be cached under [<method-signature>,aa,8]
anExpensiveLoadMethod("aa",8);
// load operation will not be called, result will taken from cache with key: [<method-signature>,aa,8]
anExpensiveLoadMethod("aa",8);
The following behaviour can be customized:
- key generation strategy (you might want to ignore some parameters in your key; you might want to use a primary key within a parameter for caching and not the parameter itself; date handling...)
- time to live strategy
- cache selection strategy
19.10.2008
|