1 /**
2 * Copyright 2009-2019 the original author or authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.apache.ibatis.annotations;
17
18 import java.lang.annotation.Documented;
19 import java.lang.annotation.ElementType;
20 import java.lang.annotation.Retention;
21 import java.lang.annotation.RetentionPolicy;
22 import java.lang.annotation.Target;
23
24 import org.apache.ibatis.cache.Cache;
25 import org.apache.ibatis.cache.decorators.LruCache;
26 import org.apache.ibatis.cache.impl.PerpetualCache;
27
28 /**
29 * The annotation that specify to use cache on namespace(e.g. mapper interface).
30 *
31 * <p><br>
32 * <b>How to use:</b>
33 * <pre>
34 * @acheNamespace(implementation = CustomCache.class, properties = {
35 * @Property(name = "host", value = "${mybatis.cache.host}"),
36 * @Property(name = "port", value = "${mybatis.cache.port}"),
37 * @Property(name = "name", value = "usersCache")
38 * })
39 * public interface UserMapper {
40 * // ...
41 * }
42 * </pre>
43 * @author Clinton Begin
44 * @author Kazuki Shimizu
45 */
46 @Documented
47 @Retention(RetentionPolicy.RUNTIME)
48 @Target(ElementType.TYPE)
49 public @interface CacheNamespace {
50
51 /**
52 * Returns the cache implementation type to use.
53 *
54 * @return the cache implementation type
55 */
56 Class<? extends Cache> implementation() default PerpetualCache.class;
57
58 /**
59 * Returns the cache evicting implementation type to use.
60 *
61 * @return the cache evicting implementation type
62 */
63 Class<? extends Cache> eviction() default LruCache.class;
64
65 /**
66 * Returns the flush interval.
67 *
68 * @return the flush interval
69 */
70 long flushInterval() default 0;
71
72 /**
73 * Return the cache size.
74 *
75 * @return the cache size
76 */
77 int size() default 1024;
78
79 /**
80 * Returns whether use read/write cache.
81 *
82 * @return {@code true} if use read/write cache; {@code false} if otherwise
83 */
84 boolean readWrite() default true;
85
86 /**
87 * Returns whether block the cache at request time or not.
88 *
89 * @return {@code true} if block the cache; {@code false} if otherwise
90 */
91 boolean blocking() default false;
92
93 /**
94 * Returns property values for a implementation object.
95 *
96 * @return property values
97 * @since 3.4.2
98 */
99 Property[] properties() default {};
100
101 }