yangys
2024-05-11 522dafb06be3374f27d087c370bcf06027e0f1cc
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
package com.qianwen.core.redis.cache;
 
import java.time.Duration;
import com.qianwen.core.tool.utils.ObjectUtil;
import com.qianwen.core.tool.utils.StringUtil;
import org.springframework.lang.Nullable;
 
public interface ICacheKey {
    String getPrefix();
 
    @Nullable
    default Duration getExpire() {
        return null;
    }
 
    default CacheKey getKey(Object... suffix) {
        String key;
        String prefix = getPrefix();
        if (ObjectUtil.isEmpty(suffix)) {
            key = prefix;
        } else {
            key = prefix.concat(StringUtil.join(suffix, ":"));
        }
        Duration expire = getExpire();
        return expire == null ? new CacheKey(key) : new CacheKey(key, expire);
    }
}