Pu Zhibing
2025-02-19 8f45afced0c6a4085560c62dbd58e6ef0f4cecf4
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
package com.ruoyi.framework.web.service;
 
import java.util.Set;
import java.util.TreeSet;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.stereotype.Service;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.utils.CacheUtils;
 
/**
 * 缓存操作处理
 * 
 * @author ruoyi
 */
@Service
public class CacheService
{
    /**
     * 获取所有缓存名称
     * 
     * @return 缓存列表
     */
    public String[] getCacheNames()
    {
        String[] cacheNames = CacheUtils.getCacheNames();
        return ArrayUtils.removeElement(cacheNames, Constants.SYS_AUTH_CACHE);
    }
 
    /**
     * 根据缓存名称获取所有键名
     * 
     * @param cacheName 缓存名称
     * @return 键名列表
     */
    public Set<String> getCacheKeys(String cacheName)
    {
        return new TreeSet<>(CacheUtils.getCache(cacheName).keys());
    }
 
    /**
     * 根据缓存名称和键名获取内容值
     * 
     * @param cacheName 缓存名称
     * @param cacheKey 键名
     * @return 键值
     */
    public Object getCacheValue(String cacheName, String cacheKey)
    {
        return CacheUtils.get(cacheName, cacheKey);
    }
 
    /**
     * 根据名称删除缓存信息
     * 
     * @param cacheName 缓存名称
     */
    public void clearCacheName(String cacheName)
    {
        CacheUtils.removeAll(cacheName);
    }
 
    /**
     * 根据名称和键名删除缓存信息
     * 
     * @param cacheName 缓存名称
     * @param cacheKey 键名
     */
    public void clearCacheKey(String cacheName, String cacheKey)
    {
        CacheUtils.remove(cacheName, cacheKey);
    }
 
    /**
     * 清理所有缓存
     */
    public void clearAll()
    {
        String[] cacheNames = getCacheNames();
        for (String cacheName : cacheNames)
        {
            CacheUtils.removeAll(cacheName);
        }
    }
}