javax.cache.annotation
Annotation Type CachePut


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

When a method annotated with CachePut is invoked a CacheKey will be generated and Cache.put(Object, Object) will be invoked on the specified cache storing the value marked with CacheValue. Null values will never be cached.

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) {
     ...
   }
 }
 

Since:
1.0
Author:
Eric Dalquist, Rick Hightower
See Also:
CacheValue

Optional Element Summary
 boolean afterInvocation
          (Optional) When Cache.put(Object, Object) should be called.
 Class<? extends CacheKeyGenerator> cacheKeyGenerator
          (Optional) The CacheKeyGenerator to use to generate the cache key used to call Cache.put(Object, Object)

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

 String cacheName
          (Optional) name of the cache.
 Class<? extends CacheResolverFactory> cacheResolverFactory
          (Optional) The CacheResolverFactory to use to find the CacheResolver the intercepter will interact with.
 

cacheName

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

If not specified defaults first to CacheDefaults.cacheName() an if that is not set it defaults to: package.name.ClassName.methodName(package.ParameterType,package.ParameterType)

Default:
""

afterInvocation

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

Default:
true

cacheResolverFactory

public abstract Class<? extends CacheResolverFactory> cacheResolverFactory
(Optional) The CacheResolverFactory to use to find the CacheResolver the intercepter will interact with.

Defaults to resolving 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 cache key used to call Cache.put(Object, Object)

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

Default:
javax.cache.annotation.CacheKeyGenerator.class


Copyright © 2011. All Rights Reserved.