@Target(value={METHOD,TYPE}) @Retention(value=RUNTIME) public @interface CachePut
CachePut
is invoked a GeneratedCacheKey
will be generated and Cache.put(Object,
Object)
will be invoked on the specified cache storing the value marked with
CacheValue
.
The default behavior is to call Cache.put(Object, Object)
after the annotated method is invoked, this behavior can be changed by setting
afterInvocation()
to false in which case
Cache.put(Object, Object)
will be called before the annotated method is
invoked.
Example of caching the Domain object with a key generated from the String and
int parameters. The CacheValue
annotation is used to designate which
parameter should be stored in the "domainDao" cache.
package my.app;
public class DomainDao {
@CachePut(cacheName="domainCache")
public void updateDomain(String domainId, int index, @CacheValue Domain
domain) {
...
}
}
Exception Handling, only used if afterInvocation()
is true.
cacheFor()
and noCacheFor()
are both empty then all
exceptions prevent the putcacheFor()
is specified and noCacheFor()
is not
specified then only exceptions that pass an instanceof check against the
cacheFor list result in a putnoCacheFor()
is specified and cacheFor()
is not
specified then all exceptions that do not pass an instanceof check against the
noCacheFor result in a putcacheFor()
and noCacheFor()
are both specified then
exceptions that pass an instanceof check against the cacheFor list but do not
pass an instanceof check against the noCacheFor list result in a putCacheValue
,
CacheKey
Modifier and Type | Optional Element and Description |
---|---|
boolean |
afterInvocation
When
Cache.put(Object, Object) should be called. |
Class<? extends Throwable>[] |
cacheFor
|
Class<? extends CacheKeyGenerator> |
cacheKeyGenerator
The
CacheKeyGenerator to use to generate the GeneratedCacheKey for interacting with the specified Cache. |
String |
cacheName
The name of the cache.
|
Class<? extends CacheResolverFactory> |
cacheResolverFactory
The
CacheResolverFactory used to find the CacheResolver to
use at runtime. |
Class<? extends Throwable>[] |
noCacheFor
|
public abstract String cacheName
If not specified defaults first to CacheDefaults.cacheName()
and if
that is not set it defaults to:
package.name.ClassName.methodName(package.ParameterType,package.ParameterType)
public abstract boolean afterInvocation
Cache.put(Object, Object)
should be called. If true it is called
after the annotated method invocation completes successfully. If false it is
called before the annotated method is invoked.
Defaults to true.
If true and the annotated method throws an exception the rules governing
cacheFor()
and noCacheFor()
will be followed.
public abstract Class<? extends CacheResolverFactory> cacheResolverFactory
CacheResolverFactory
used to find the CacheResolver
to
use at runtime.
The default resolver pair will resolve the cache by name from the default
CacheManager
public abstract Class<? extends CacheKeyGenerator> cacheKeyGenerator
CacheKeyGenerator
to use to generate the GeneratedCacheKey
for interacting with the specified Cache.
Defaults to a key generator that uses Arrays.deepHashCode(Object[])
and Arrays.deepEquals(Object[], Object[])
with the array
returned by CacheKeyInvocationContext.getKeyParameters()
CacheKey
public abstract Class<? extends Throwable>[] cacheFor
classes
, that must be a
subclass of Throwable
, indicating the exception types that must
cause the parameter to be cached. Only used if afterInvocation()
is
true.public abstract Class<? extends Throwable>[] noCacheFor
Classes
, which must be a
subclass of Throwable
, indicating which exception types must
not cause the parameter to be cached. Only used if
afterInvocation()
is true.Copyright © 2014. All Rights Reserved.