Annotation Type CacheRemove
-
@Target({METHOD,TYPE}) @Retention(RUNTIME) public @interface CacheRemove
When a method annotated withCacheRemove
is invoked aGeneratedCacheKey
will be generated andCache.remove(Object)
will be invoked on the specified cache.The default behavior is to call
Cache.remove(Object)
after the annotated method is invoked, this behavior can be changed by settingafterInvocation()
to false in which caseCache.remove(Object)
will be called before the annotated method is invoked.Example of removing a specific Domain object from the "domainCache". A
GeneratedCacheKey
will be generated from the String and int parameters and used to callCache.remove(Object)
after the deleteDomain method completes successfully.package my.app; public class DomainDao { @CacheRemove(cacheName="domainCache") public void deleteDomain(String domainId, int index) { ... } }
Exception Handling, only used if
afterInvocation()
is true.- If
evictFor()
andnoEvictFor()
are both empty then all exceptions prevent the remove - If
evictFor()
is specified andnoEvictFor()
is not specified then only exceptions that pass an instanceof check against the evictFor list result in a remove - If
noEvictFor()
is specified andevictFor()
is not specified then all exceptions that do not pass an instanceof check against the noEvictFor result in a remove - If
evictFor()
andnoEvictFor()
are both specified then exceptions that pass an instanceof check against the evictFor list but do not pass an instanceof check against the noEvictFor list result in a remove
- Since:
- 1.0
- Author:
- Eric Dalquist, Rick Hightower, Greg Luck
- See Also:
CacheKey
- If
-
-
Optional Element Summary
Optional Elements Modifier and Type Optional Element Description boolean
afterInvocation
WhenCache.remove(Object)
should be called.Class<? extends CacheKeyGenerator>
cacheKeyGenerator
TheCacheKeyGenerator
to use to generate theGeneratedCacheKey
for interacting with the specified Cache.String
cacheName
The name of the cache.Class<? extends CacheResolverFactory>
cacheResolverFactory
TheCacheResolverFactory
used to find theCacheResolver
to use at runtime.Class<? extends Throwable>[]
evictFor
Class<? extends Throwable>[]
noEvictFor
-
-
-
Element Detail
-
cacheName
String cacheName
The name of the cache.If not specified defaults first to
CacheDefaults.cacheName()
, and if that is not set then to: package.name.ClassName.methodName(package.ParameterType,package.ParameterType)- Default:
- ""
-
-
-
afterInvocation
boolean afterInvocation
WhenCache.remove(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 remove will not be executed.
- Default:
- true
-
-
-
cacheResolverFactory
Class<? extends CacheResolverFactory> cacheResolverFactory
TheCacheResolverFactory
used to find theCacheResolver
to use at runtime.The default resolver pair will resolve the cache by name from the default
CacheManager
- Default:
- javax.cache.annotation.CacheResolverFactory.class
-
-
-
cacheKeyGenerator
Class<? extends CacheKeyGenerator> cacheKeyGenerator
TheCacheKeyGenerator
to use to generate theGeneratedCacheKey
for 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
-
-
-
evictFor
Class<? extends Throwable>[] evictFor
Defines zero (0) or more exceptionclasses
, that must be a subclass ofThrowable
, indicating the exception types that must cause a cache eviction. Only used ifafterInvocation()
is true.- Default:
- {}
-
-
-
noEvictFor
Class<? extends Throwable>[] noEvictFor
Defines zero (0) or more exceptionClasses
, that must be a subclass ofThrowable
, indicating the exception types that must not cause a cache eviction. Only used ifafterInvocation()
is true.- Default:
- {}
-
-