CacheService.java
1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package com.infoloop.tianting.cache;
/**
* 缓存服务接口
* 定义了缓存的基本操作方法
*/
public interface CacheService {
/**
* 获取缓存
* @param key 缓存key
* @return 缓存的值,如果不存在返回null
*/
Object get(String key);
/**
* 设置缓存
* @param key 缓存key
* @param value 缓存值
* @param ttlSeconds 过期时间(秒)
*/
void put(String key, Object value, int ttlSeconds);
/**
* 删除缓存
* @param key 缓存key
*/
void evict(String key);
/**
* 删除缓存(别名方法)
* @param key 缓存key
*/
default void delete(String key) {
evict(key);
}
/**
* 根据前缀删除缓存
* @param prefix 缓存key前缀
*/
void evictByPrefix(String prefix);
/**
* 根据模式删除缓存
* @param pattern 缓存key模式(支持通配符*)
*/
default void deleteByPattern(String pattern) {
evictByPrefix(pattern.replace("*", ""));
}
/**
* 清空所有缓存
*/
void clear();
/**
* 获取缓存统计信息
* @return 缓存统计信息
*/
CacheStats getStats();
/**
* 检查缓存是否存在
* @param key 缓存key
* @return true表示存在,false表示不存在
*/
boolean exists(String key);
/**
* 获取缓存剩余过期时间
* @param key 缓存key
* @return 剩余时间(秒),-2表示key不存在,-1表示永久
*/
long getExpire(String key);
}