All Downloads are FREE. Search and download functionalities are using the official Maven repository.

javax.cache.annotation.CacheRemove Maven / Gradle / Ivy

Go to download

Easy Redis Java client and Real-Time Data Platform. Valkey compatible. Sync/Async/RxJava3/Reactive API. Client side caching. Over 50 Redis based Java objects and services: JCache API, Apache Tomcat, Hibernate, Spring, Set, Multimap, SortedSet, Map, List, Queue, Deque, Semaphore, Lock, AtomicLong, Map Reduce, Bloom filter, Scheduler, RPC

There is a newer version: 3.40.2
Show newest version
/**
 * Copyright 2011-2016 Terracotta, Inc.
 * Copyright 2011-2016 Oracle America Incorporated
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package javax.cache.annotation;

import javax.cache.Cache;
import javax.cache.CacheManager;
import javax.enterprise.util.Nonbinding;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;


/**
 * When a method annotated with {@link CacheRemove} is invoked a {@link
 * GeneratedCacheKey} will be generated and {@link Cache#remove(Object)} will be
 * invoked on the specified cache.
 * 

* The default behavior is to call {@link Cache#remove(Object)} after * the annotated method is invoked, this behavior can be changed by setting * {@link #afterInvocation()} to false in which case * {@link Cache#remove(Object)} will be called before the annotated * method is invoked. *

* Example of removing a specific Domain object from the "domainCache". A {@link * GeneratedCacheKey} will be generated from the String and int parameters and * used to call {@link 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 {@link #afterInvocation()} is true. *

    *
  1. If {@link #evictFor()} and {@link #noEvictFor()} are both empty then all * exceptions prevent the remove
  2. *
  3. If {@link #evictFor()} is specified and {@link #noEvictFor()} is not * specified then only exceptions that pass an instanceof check against the * evictFor list result in a remove
  4. *
  5. If {@link #noEvictFor()} is specified and {@link #evictFor()} is not * specified then all exceptions that do not pass an instanceof check against the * noEvictFor result in a remove
  6. *
  7. If {@link #evictFor()} and {@link #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
  8. *
* * @author Eric Dalquist * @author Rick Hightower * @author Greg Luck * @see CacheKey * @since 1.0 */ @Target({ElementType.METHOD, ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) public @interface CacheRemove { /** * The name of the cache. *

* If not specified defaults first to {@link CacheDefaults#cacheName()}, * and if that is not set then to: * package.name.ClassName.methodName(package.ParameterType,package.ParameterType) */ @Nonbinding String cacheName() default ""; /** * When {@link 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. */ @Nonbinding boolean afterInvocation() default true; /** * The {@link CacheResolverFactory} used to find the {@link CacheResolver} to * use at runtime. *

* The default resolver pair will resolve the cache by name from the default * {@link CacheManager} */ @Nonbinding Class cacheResolverFactory() default CacheResolverFactory.class; /** * The {@link CacheKeyGenerator} to use to generate the {@link * GeneratedCacheKey} for interacting with the specified Cache. *

* Defaults to a key generator that uses * {@link java.util.Arrays#deepHashCode(Object[])} * and {@link java.util.Arrays#deepEquals(Object[], Object[])} with the array * returned by {@link CacheKeyInvocationContext#getKeyParameters()} * * @see CacheKey */ @Nonbinding Class cacheKeyGenerator() default CacheKeyGenerator.class; /** * Defines zero (0) or more exception {@link Class classes}, that must be a * subclass of {@link Throwable}, indicating the exception types that must cause * a cache eviction. Only used if {@link #afterInvocation()} is true. */ @Nonbinding Class[] evictFor() default {}; /** * Defines zero (0) or more exception {@link Class Classes}, that must be a * subclass of {@link Throwable}, indicating the exception types that must * not cause a cache eviction. Only used if {@link #afterInvocation()} is * true. */ @Nonbinding Class[] noEvictFor() default {}; }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy