inleft
2022-02-09 9bcb19959eeb9da9bde2561e7278f6d0a55eb151
commit | author | age
9bcb19 1 /*
I 2 Copyright [2020] [https://www.xiaonuo.vip]
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 Snowy采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点:
17
18 1.请不要删除和修改根目录下的LICENSE文件。
19 2.请不要删除和修改Snowy源码头部的版权声明。
20 3.请保留源码和相关描述文件的项目出处,作者声明等。
21 4.分发源码时候,请注明软件出处 https://gitee.com/xiaonuobase/snowy
22 5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/xiaonuobase/snowy
23 6.若您的项目无法满足以上几点,可申请商业授权,获取Snowy商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip
24  */
25 package vip.xiaonuo.core.cache;
26
27 import java.util.Collection;
28 import java.util.Map;
29
30 /**
31  * 缓存操作的基础接口,可以实现不同种缓存实现
32  * <p>
33  * 泛型为cache的值类class类型
34  *
35  * @author yubaoshan
36  * @date 2020/7/8 22:02
37  */
38 public interface CacheOperator<T> {
39
40     /**
41      * 添加缓存
42      *
43      * @param key   键
44      * @param value 值
45      * @author yubaoshan
46      * @date 2020/7/8 22:06
47      */
48     void put(String key, T value);
49
50     /**
51      * 添加缓存(带过期时间,单位是秒)
52      *
53      * @param key            键
54      * @param value          值
55      * @param timeoutSeconds 过期时间,单位秒
56      * @author yubaoshan
57      * @date 2020/7/8 22:07
58      */
59     void put(String key, T value, Long timeoutSeconds);
60
61     /**
62      * 通过缓存key获取缓存
63      *
64      * @param key 键
65      * @return 值
66      * @author yubaoshan
67      * @date 2020/7/8 22:08
68      */
69     Object get(String key);
70
71     /**
72      * 删除缓存
73      *
74      * @param key 键,多个
75      * @author yubaoshan
76      * @date 2020/7/8 22:09
77      */
78     void remove(String... key);
79
80     /**
81      * 获得缓存的所有key列表(不带common prefix的)
82      *
83      * @return key列表
84      * @author yubaoshan
85      * @date 2020/7/8 22:11
86      */
87     Collection<String> getAllKeys();
88
89     /**
90      * 获得缓存的所有值列表
91      *
92      * @return 值列表
93      * @author yubaoshan
94      * @date 2020/7/8 22:11
95      */
96     Collection<T> getAllValues();
97
98     /**
99      * 获取所有的key,value
100      *
101      * @return 键值map
102      * @author yubaoshan
103      * @date 2020/7/8 22:11
104      */
105     Map<String, T> getAllKeyValues();
106
107     /**
108      * 通用缓存的前缀,用于区分不同业务
109      * <p>
110      * 如果带了前缀,所有的缓存在添加的时候,key都会带上这个前缀
111      *
112      * @return 缓存前缀
113      * @author yubaoshan
114      * @date 2020/7/9 11:06
115      */
116     String getCommonKeyPrefix();
117
118 }