1 /*
2 * Copyright 2009-2024 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 * https://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 * <p>
31 * <b>How to use:</b>
32 *
33 * <pre>{@code
34 * @CacheNamespace(implementation = CustomCache.class, properties = {
35 * @Property(name = "host", value = "${mybatis.cache.host}"),
36 * @Property(name = "port", value = "${mybatis.cache.port}"), @Property(name = "name", value = "usersCache") })
37 * public interface UserMapper {
38 * // ...
39 * }
40 * }</pre>
41 *
42 * @author Clinton Begin
43 * @author Kazuki Shimizu
44 */
45 @Documented
46 @Retention(RetentionPolicy.RUNTIME)
47 @Target(ElementType.TYPE)
48 public @interface CacheNamespace {
49
50 /**
51 * Returns the cache implementation type to use.
52 *
53 * @return the cache implementation type
54 */
55 Class<? extends Cache> implementation() default PerpetualCache.class;
56
57 /**
58 * Returns the cache evicting implementation type to use.
59 *
60 * @return the cache evicting implementation type
61 */
62 Class<? extends Cache> eviction() default LruCache.class;
63
64 /**
65 * Returns the flush interval.
66 *
67 * @return the flush interval
68 */
69 long flushInterval() default 0;
70
71 /**
72 * Return the cache size.
73 *
74 * @return the cache size
75 */
76 int size() default 1024;
77
78 /**
79 * Returns whether use read/write cache.
80 *
81 * @return {@code true} if use read/write cache; {@code false} if otherwise
82 */
83 boolean readWrite() default true;
84
85 /**
86 * Returns whether block the cache at request time or not.
87 *
88 * @return {@code true} if block the cache; {@code false} if otherwise
89 */
90 boolean blocking() default false;
91
92 /**
93 * Returns property values for a implementation object.
94 *
95 * @return property values
96 *
97 * @since 3.4.2
98 */
99 Property[] properties() default {};
100
101 }