-
Notifications
You must be signed in to change notification settings - Fork 1
Cache
The Cache
annotation indicates that the annotated method is eligible for caching, meaning subsequent invocations of a method for which the result has been cached, with the same arguments, will return the cached value without having to actually execute the method. This is particularly useful for computation- or resource- intensive code. Caches can be cleared using the EvictCache annotation.
In order to make use of cache abstraction, it must be enabled in infinitum.cfg.xml:
<property name="methodCaching">true</property>
The Cache
annotation has a single attribute, value
, which declares the name of the cache to use.
The example below illustrates how a method can be marked cacheable using the Cache
annotation. The value returned by the method getFoo
is stored in a cache named fooCache
for the given string argument. Subsequent invocations of getFoo
with the same argument will return the cached value instead of executing the method.
@Cache("fooCache")
public Foo getFoo(String string) {
Foo foo = someExpensiveOperation(string);
return foo;
}