Top Description Methods
javax.cache.annotation

public @Interface CacheRemove

extends Annotation
Annotations
@Target:METHOD, TYPE
@Retention:RUNTIME
Imports
javax.cache.Cache, .CacheManager, javax.enterprise.util.Nonbinding, java.lang.annotation.ElementType, .Retention, .RetentionPolicy, .Target

When a method annotated with CacheRemove is invoked a GeneratedCacheKey will be generated and Cache#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 setting afterInvocation() to false in which case Cache#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 call Cache#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.

  1. If evictFor() and noEvictFor() are both empty then all exceptions prevent the remove
  2. If evictFor() is specified and noEvictFor() is not specified then only exceptions that pass an instanceof check against the evictFor list result in a remove
  3. If noEvictFor() is specified and evictFor() is not specified then all exceptions that do not pass an instanceof check against the noEvictFor result in a remove
  4. If evictFor() and noEvictFor() 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
Authors
Eric Dalquist, Rick Hightower, Greg Luck
Since
1.0
See Also
CacheKey

Method Summary

Modifier and TypeMethod and Description
public boolean
afterInvocation()

When Cache#remove(Object) should be called.

public Class<? extends CacheKeyGenerator>
cacheKeyGenerator()

The CacheKeyGenerator to use to generate the GeneratedCacheKey for interacting with the specified Cache.

public String
cacheName()

The name of the cache.

public Class<? extends CacheResolverFactory>
cacheResolverFactory()

The CacheResolverFactory used to find the CacheResolver to use at runtime.

public Class<? extends Throwable>[]
evictFor()

Defines zero (0) or more exception classes, that must be a subclass of Throwable, indicating the exception types that must cause a cache eviction.

public Class<? extends Throwable>[]
noEvictFor()

Defines zero (0) or more exception Classes, that must be a subclass of Throwable, indicating the exception types that must not cause a cache eviction.

Inherited from java.lang.annotation.Annotation:
annotationTypeequalshashCodetoString

Method Detail

afterInvocationback to summary
public boolean afterInvocation()

When Cache#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.

Annotations
@Nonbinding
cacheKeyGeneratorback to summary
public Class<? extends CacheKeyGenerator> cacheKeyGenerator()

The CacheKeyGenerator to use to generate the GeneratedCacheKey for interacting with the specified Cache.

Defaults to a key generator that uses java.util.Arrays#deepHashCode(Object[]) and java.util.Arrays#deepEquals(Object[], Object[]) with the array returned by CacheKeyInvocationContext#getKeyParameters()

Annotations
@Nonbinding
See Also
CacheKey
cacheNameback to summary
public 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)

Annotations
@Nonbinding
cacheResolverFactoryback to summary
public Class<? extends CacheResolverFactory> cacheResolverFactory()

The CacheResolverFactory used to find the CacheResolver to use at runtime.

The default resolver pair will resolve the cache by name from the default CacheManager

Annotations
@Nonbinding
evictForback to summary
public Class<? extends Throwable>[] evictFor()

Defines zero (0) or more exception classes, that must be a subclass of Throwable, indicating the exception types that must cause a cache eviction. Only used if afterInvocation() is true.

Annotations
@Nonbinding
noEvictForback to summary
public Class<? extends Throwable>[] noEvictFor()

Defines zero (0) or more exception Classes, that must be a subclass of Throwable, indicating the exception types that must not cause a cache eviction. Only used if afterInvocation() is true.

Annotations
@Nonbinding