|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2014 the original author or authors. |
| 2 | + * Copyright 2002-2015 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
23 | 23 | import java.lang.annotation.RetentionPolicy;
|
24 | 24 | import java.lang.annotation.Target;
|
25 | 25 |
|
26 |
| -import org.springframework.cache.Cache; |
27 |
| - |
28 | 26 | /**
|
29 |
| - * Annotation indicating that a method (or all methods on a class) trigger(s) |
30 |
| - * a {@link Cache#put(Object, Object)} operation. As opposed to {@link Cacheable} annotation, |
31 |
| - * this annotation does not cause the target method to be skipped - rather it |
32 |
| - * always causes the method to be invoked and its result to be placed into the cache. |
| 27 | + * Annotation indicating that a method (or all methods on a class) triggers a |
| 28 | + * {@link org.springframework.cache.Cache#put(Object, Object) cache put} operation. |
| 29 | + * |
| 30 | + * <p>In contrast to the {@link Cacheable @Cacheable} annotation, this annotation |
| 31 | + * does not cause the advised method to be skipped. Rather, it always causes the |
| 32 | + * method to be invoked and its result to be stored in the associated cache. |
33 | 33 | *
|
34 | 34 | * @author Costin Leau
|
35 | 35 | * @author Phillip Webb
|
36 | 36 | * @author Stephane Nicoll
|
37 | 37 | * @since 3.1
|
38 | 38 | * @see CacheConfig
|
39 | 39 | */
|
40 |
| -@Target({ ElementType.METHOD, ElementType.TYPE }) |
| 40 | +@Target({ElementType.METHOD, ElementType.TYPE}) |
41 | 41 | @Retention(RetentionPolicy.RUNTIME)
|
42 | 42 | @Inherited
|
43 | 43 | @Documented
|
44 | 44 | public @interface CachePut {
|
45 | 45 |
|
46 | 46 | /**
|
47 |
| - * Name of the caches in which the update takes place. |
48 |
| - * <p>May be used to determine the target cache (or caches), matching the |
49 |
| - * qualifier value (or the bean name(s)) of (a) specific bean definition. |
| 47 | + * Names of the caches to use for the cache put operation. |
| 48 | + * <p>Names may be used to determine the target cache (or caches), matching |
| 49 | + * the qualifier value or bean name of a specific bean definition. |
| 50 | + * @see CacheConfig#cacheNames |
50 | 51 | */
|
51 | 52 | String[] value() default {};
|
52 | 53 |
|
53 | 54 | /**
|
54 |
| - * Spring Expression Language (SpEL) attribute for computing the key dynamically. |
55 |
| - * <p>Default is "", meaning all method parameters are considered as a key, unless |
56 |
| - * a custom {@link #keyGenerator()} has been set. |
| 55 | + * Spring Expression Language (SpEL) expression for computing the key dynamically. |
| 56 | + * <p>Default is {@code ""}, meaning all method parameters are considered as a key, |
| 57 | + * unless a custom {@link #keyGenerator} has been set. |
| 58 | + * <p>The SpEL expression evaluates again a dedicated context that provides the |
| 59 | + * following meta-data: |
| 60 | + * <ul> |
| 61 | + * <li>{@code #result} for a reference to the result of the method invocation.</li> |
| 62 | + * <li>{@code #root.method}, {@code #root.target} and {@code #root.caches} for a |
| 63 | + * reference to the {@link java.lang.reflect.Method method}, target object and |
| 64 | + * affected cache(s) respectively.</li> |
| 65 | + * <li>Shortcuts for the method name ({@code #root.methodName}) and target class |
| 66 | + * ({@code #root.targetClass}) are also available. |
| 67 | + * <li>Method arguments can be accessed by index. For instance the second argument |
| 68 | + * can be access via {@code #root.args[1]}, {@code #p1} or {@code #a1}. Arguments |
| 69 | + * can also be accessed by name if that information is available.</li> |
| 70 | + * </ul> |
57 | 71 | */
|
58 | 72 | String key() default "";
|
59 | 73 |
|
60 | 74 | /**
|
61 |
| - * The bean name of the custom {@link org.springframework.cache.interceptor.KeyGenerator} to use. |
62 |
| - * <p>Mutually exclusive with the {@link #key()} attribute. |
| 75 | + * The bean name of the custom {@link org.springframework.cache.interceptor.KeyGenerator} |
| 76 | + * to use. |
| 77 | + * <p>Mutually exclusive with the {@link #key} attribute. |
| 78 | + * @see CacheConfig#keyGenerator |
63 | 79 | */
|
64 | 80 | String keyGenerator() default "";
|
65 | 81 |
|
66 | 82 | /**
|
67 | 83 | * The bean name of the custom {@link org.springframework.cache.CacheManager} to use to
|
68 | 84 | * create a default {@link org.springframework.cache.interceptor.CacheResolver} if none
|
69 | 85 | * is set already.
|
70 |
| - * <p>Mutually exclusive with the {@link #cacheResolver()} attribute. |
| 86 | + * <p>Mutually exclusive with the {@link #cacheResolver} attribute. |
71 | 87 | * @see org.springframework.cache.interceptor.SimpleCacheResolver
|
| 88 | + * @see CacheConfig#cacheManager |
72 | 89 | */
|
73 | 90 | String cacheManager() default "";
|
74 | 91 |
|
75 | 92 | /**
|
76 |
| - * The bean name of the custom {@link org.springframework.cache.interceptor.CacheResolver} to use. |
| 93 | + * The bean name of the custom {@link org.springframework.cache.interceptor.CacheResolver} |
| 94 | + * to use. |
| 95 | + * @see CacheConfig#cacheResolver |
77 | 96 | */
|
78 | 97 | String cacheResolver() default "";
|
79 | 98 |
|
80 | 99 | /**
|
81 |
| - * Spring Expression Language (SpEL) attribute used for conditioning the cache update. |
82 |
| - * <p>Default is "", meaning the method result is always cached. |
| 100 | + * Spring Expression Language (SpEL) expression used for making the cache |
| 101 | + * put operation conditional. |
| 102 | + * <p>Default is {@code ""}, meaning the method result is always cached. |
| 103 | + * <p>The SpEL expression evaluates again a dedicated context that provides the |
| 104 | + * following meta-data: |
| 105 | + * <ul> |
| 106 | + * <li>{@code #root.method}, {@code #root.target} and {@code #root.caches} for a |
| 107 | + * reference to the {@link java.lang.reflect.Method method}, target object and |
| 108 | + * affected cache(s) respectively.</li> |
| 109 | + * <li>Shortcuts for the method name ({@code #root.methodName}) and target class |
| 110 | + * ({@code #root.targetClass}) are also available. |
| 111 | + * <li>Method arguments can be accessed by index. For instance the second argument |
| 112 | + * can be access via {@code #root.args[1]}, {@code #p1} or {@code #a1}. Arguments |
| 113 | + * can also be accessed by name if that information is available.</li> |
| 114 | + * </ul> |
83 | 115 | */
|
84 | 116 | String condition() default "";
|
85 | 117 |
|
86 | 118 | /**
|
87 |
| - * Spring Expression Language (SpEL) attribute used to veto the cache update. |
88 |
| - * <p>Unlike {@link #condition()}, this expression is evaluated after the method |
89 |
| - * has been called and can therefore refer to the {@code result}. Default is "", |
90 |
| - * meaning that caching is never vetoed. |
| 119 | + * Spring Expression Language (SpEL) expression used to veto the cache put operation. |
| 120 | + * <p>Unlike {@link #condition}, this expression is evaluated after the method |
| 121 | + * has been called and can therefore refer to the {@code result}. |
| 122 | + * <p>Default is {@code ""}, meaning that caching is never vetoed. |
| 123 | + * <p>The SpEL expression evaluates again a dedicated context that provides the |
| 124 | + * following meta-data: |
| 125 | + * <ul> |
| 126 | + * <li>{@code #result} for a reference to the result of the method invocation.</li> |
| 127 | + * <li>{@code #root.method}, {@code #root.target} and {@code #root.caches} for a |
| 128 | + * reference to the {@link java.lang.reflect.Method method}, target object and |
| 129 | + * affected cache(s) respectively.</li> |
| 130 | + * <li>Shortcuts for the method name ({@code #root.methodName}) and target class |
| 131 | + * ({@code #root.targetClass}) are also available. |
| 132 | + * <li>Method arguments can be accessed by index. For instance the second argument |
| 133 | + * can be access via {@code #root.args[1]}, {@code #p1} or {@code #a1}. Arguments |
| 134 | + * can also be accessed by name if that information is available.</li> |
| 135 | + * </ul> |
91 | 136 | * @since 3.2
|
92 | 137 | */
|
93 | 138 | String unless() default "";
|
| 139 | + |
94 | 140 | }
|
0 commit comments