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