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