CacheEnum.java
2.93 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package com.yohoufo.user.constants;
import org.apache.commons.lang3.StringUtils;
import com.yoho.core.config.ConfigReaderUtil;
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
/**
* Created by shengguo.cai on 2018/9/18.
*/
public enum CacheEnum {
/**
* 消息盒子-某类型下未读消息总数,缓存5分钟
*/
USERS_INBOX_TYPE_UNREADCOUNT("yh:users:inbox_type_unreadcount", 5 * 60, "users.cachetime.inbox_type_unreadcount"),
/**
* 消息盒子-消息,缓存5分钟
*/
// USERS_INBOX_LIST("yh:users:inbox_list", 5 * 60, "users.cachetime.inbox_list"),
/**
* 消息盒子-消息,缓存5分钟
*/
USERS_INBOX_VO_LIST("yh:users:inbox_vo_list", 5 * 60, "users.cachetime.inbox_list"),
/**
* 消息盒子-消息总数,缓存5分钟
*/
USERS_INBOX_LIST_TOTAL("yh:users:inbox_list_total", 5 * 60, "users.cachetime.inbox_list_total"),
/**
* 消息盒子-是否是新消息引导,缓存20分钟
*/
USERS_INBOX_NEW_MARK("ufo:users:inbox_new_mark", 24 * 60 * 60, "ufo.users.cachetime.inbox_new_mark"),
/**
* 消息盒子-最新一条消息,缓存5分钟
*/
USERS_INBOX_VO_LAST_INFO("ufo:users:inbox_last_info", 5 * 60, "users.cachetime.inbox_last_info"),
/**
* 消息盒子-未读消息总数,缓存5分钟
*/
USERS_INBOX_LIST_UNREAD_TOTAL("ufo:users:inbox_list_total", 5 * 60, "users.cachetime.inbox_unread_total"),
/*
* end
*/;
private static final long DEFAULT_BACKUP_CACHE_TIME = 12 * 60 * 60;
private final String keyPrefix;
private final long cacheTime;
private String cacheTimeKey;
CacheEnum(String keyPrefix, long cacheTime) {
this.keyPrefix = keyPrefix;
this.cacheTime = cacheTime;
}
CacheEnum(String keyPrefix, long cacheTime, String cacheTimeKey) {
this.keyPrefix = keyPrefix;
this.cacheTime = cacheTime;
this.cacheTimeKey = cacheTimeKey;
}
public RedisKeyBuilder generateKey(Object... params) {
if (isEmptyArray(params)) {
return new RedisKeyBuilder().appendFixed(keyPrefix);
} else {
return new RedisKeyBuilder().appendFixed(keyPrefix).appendFixed(':').appendVar(StringUtils.join(params, '-'));
}
}
public RedisKeyBuilder generateKeyLowerCase(Object... params) {
if (isEmptyArray(params)) {
return new RedisKeyBuilder().appendFixed(keyPrefix);
} else {
return new RedisKeyBuilder().appendFixed(keyPrefix).appendFixed(':').appendVar(StringUtils.join(params, '-').toLowerCase());
}
}
private boolean isEmptyArray(Object... params) {
return params == null || params.length == 0;
}
public long getCacheTime() {
if (StringUtils.isEmpty(cacheTimeKey)) {
return cacheTime;
} else {
return ConfigReaderUtil.getLong(cacheTimeKey, cacheTime);
}
}
}