javax.cache.annotation
Annotation Type CacheRemoveEntry


@Target(value={METHOD,TYPE})
@Retention(value=RUNTIME)
public @interface CacheRemoveEntry

When a method annotated with CacheRemoveEntry is invoked a CacheKey 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 CacheKey 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 {
   @CacheRemoveEntry(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 which 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 which do not pass an instanceof check against the noEvictFor result in a remove
  4. If evictFor() and noEvictFor() are both specified then exceptions which 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
See Also:
CacheKeyParam

Optional Element Summary
 boolean afterInvocation
          (Optional) When Cache.remove(Object) should be called.
 Class<? extends CacheKeyGenerator> cacheKeyGenerator
          (Optional) The CacheKeyGenerator to use to generate the CacheKey for interacting with the specified Cache.
 String cacheName
          (Optional) name of the cache.
 Class<? extends CacheResolverFactory> cacheResolverFactory
          (Optional) The CacheResolverFactory used to find the CacheResolver to use at runtime.
 Class<? extends Throwable>[] evictFor
          Defines zero (0) or more exception classes, which must be a subclass of Throwable, indicating which exception types must cause a cache evict.
 Class<? extends Throwable>[] noEvictFor
          Defines zero (0) or more exception Classes, which must be a subclass of Throwable, indicating which exception types must not cause a cache evict.
 

cacheName

public abstract String cacheName
(Optional) name of the cache.

If not specified defaults first to CacheDefaults.cacheName(), if that is not set it a CacheAnnotationConfigurationException will be thrown by the provider.

Default:
""

afterInvocation

public abstract boolean afterInvocation
(Optional) 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 put will not be executed.

Default:
true

cacheResolverFactory

public abstract Class<? extends CacheResolverFactory> cacheResolverFactory
(Optional) 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

Default:
javax.cache.annotation.CacheResolverFactory.class

cacheKeyGenerator

public abstract Class<? extends CacheKeyGenerator> cacheKeyGenerator
(Optional) The CacheKeyGenerator to use to generate the CacheKey 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()

See Also:
CacheKeyParam
Default:
javax.cache.annotation.CacheKeyGenerator.class

evictFor

public abstract Class<? extends Throwable>[] evictFor
Defines zero (0) or more exception classes, which must be a subclass of Throwable, indicating which exception types must cause a cache evict. Only used if afterInvocation() is true.

Default:
{}

noEvictFor

public abstract Class<? extends Throwable>[] noEvictFor
Defines zero (0) or more exception Classes, which must be a subclass of Throwable, indicating which exception types must not cause a cache evict. Only used if afterInvocation() is true.

Default:
{}


Copyright © 2012. All Rights Reserved.