935090232@qq.com
2021-10-25 207ee5e38bf61343d8a4f0ac88936798593a79e7
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
package com.matrix.system.common.init;
 
import com.matrix.core.tools.LogUtil;
 
import java.util.Date;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
 
public class LocalCache {
 
 
    private static ConcurrentMap<String,Value> localCache=new ConcurrentHashMap(60);
 
    /**
     * 获取本地缓存
     * @param key
     * @param <T>
     * @return
     */
    public static <T> T get(String key){
        return (T)localCache.get(key);
    }
 
    /**
     * 保存一个本地缓存
     * @param key
     * @param value
     */
    public static void save(String key,Object value){
        if(null!=localCache.put(key,value)){
            LogUtil.debug("覆盖原有缓存{}",key);
        }
    }
 
    public static void save(String key,Object value,long timeOut){
        if(null!=localCache.put(key,value)){
            LogUtil.debug("覆盖原有缓存{}",key);
        }
    }
 
 
    /**
     * 缓存对象
     */
     class Value{
 
        /**
         * 过期时间,0 表示不过期
         */
      private long timeOut=0;
        /**
         * 缓存值
         */
      private Object value;
 
        /**
         * 缓存创建时间
         */
      private long createTime;
 
 
 
 
      public static Value build(String value,long timeOut){
          Value instances=new Value();
          instances.createTime=System.currentTimeMillis();
          instances.value=value;
          instances.timeOut=timeOut;
          return instances;
      }
 
    }
 
 
}