Annotation Type CachePut
-
@Target({METHOD,TYPE}) @Retention(RUNTIME) public @interface CachePutWhen a method annotated withCachePutis invoked aGeneratedCacheKeywill be generated andCache.put(Object, Object)will be invoked on the specified cache storing the value marked withCacheValue.The default behavior is to call
Cache.put(Object, Object)after the annotated method is invoked, this behavior can be changed by settingafterInvocation()to false in which caseCache.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
CacheValueannotation 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.- If
cacheFor()andnoCacheFor()are both empty then all exceptions prevent the put - If
cacheFor()is specified andnoCacheFor()is not specified then only exceptions that pass an instanceof check against the cacheFor list result in a put - If
noCacheFor()is specified andcacheFor()is not specified then all exceptions that do not pass an instanceof check against the noCacheFor result in a put - If
cacheFor()andnoCacheFor()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 put
- Since:
- 1.0
- See Also:
CacheValue,CacheKey
- If
-
-
Optional Element Summary
Optional Elements Modifier and Type Optional Element Description booleanafterInvocationWhenCache.put(Object, Object)should be called.java.lang.Class<? extends java.lang.Throwable>[]cacheForDefines zero (0) or more exceptionclasses, that must be a subclass ofThrowable, indicating the exception types that must cause the parameter to be cached.java.lang.Class<? extends CacheKeyGenerator>cacheKeyGeneratorTheCacheKeyGeneratorto use to generate theGeneratedCacheKeyfor interacting with the specified Cache.java.lang.StringcacheNameThe name of the cache.java.lang.Class<? extends CacheResolverFactory>cacheResolverFactoryTheCacheResolverFactoryused to find theCacheResolverto use at runtime.java.lang.Class<? extends java.lang.Throwable>[]noCacheForDefines zero (0) or more exceptionClasses, which must be a subclass ofThrowable, indicating which exception types must not cause the parameter to be cached.
-
-
-
Element Detail
-
cacheName
java.lang.String cacheName
The name of the cache.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)- Default:
- ""
-
-
-
afterInvocation
boolean afterInvocation
WhenCache.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()andnoCacheFor()will be followed.- Default:
- true
-
-
-
cacheResolverFactory
java.lang.Class<? extends CacheResolverFactory> cacheResolverFactory
TheCacheResolverFactoryused to find theCacheResolverto use at runtime.The default resolver pair will resolve the cache by name from the default
CacheManager- Default:
- javax.cache.annotation.CacheResolverFactory.class
-
-
-
cacheKeyGenerator
java.lang.Class<? extends CacheKeyGenerator> cacheKeyGenerator
TheCacheKeyGeneratorto use to generate theGeneratedCacheKeyfor interacting with the specified Cache.Defaults to a key generator that uses
Arrays.deepHashCode(Object[])andArrays.deepEquals(Object[], Object[])with the array returned byCacheKeyInvocationContext.getKeyParameters()- See Also:
CacheKey
- Default:
- javax.cache.annotation.CacheKeyGenerator.class
-
-
-
cacheFor
java.lang.Class<? extends java.lang.Throwable>[] cacheFor
Defines zero (0) or more exceptionclasses, that must be a subclass ofThrowable, indicating the exception types that must cause the parameter to be cached. Only used ifafterInvocation()is true.- Default:
- {}
-
-
-
noCacheFor
java.lang.Class<? extends java.lang.Throwable>[] noCacheFor
Defines zero (0) or more exceptionClasses, which must be a subclass ofThrowable, indicating which exception types must not cause the parameter to be cached. Only used ifafterInvocation()is true.- Default:
- {}
-
-