1 package com.foxinmy.weixin4j.cache;
2
3 import java.util.Map;
4 import java.util.concurrent.ConcurrentHashMap;
5
6
7
8
9
10
11
12
13
14
15 public class MemoryCacheStorager<T extends Cacheable> implements
16 CacheStorager<T> {
17
18 private final Map<String, T> CONMAP;
19
20 public MemoryCacheStorager() {
21 this.CONMAP = new ConcurrentHashMap<String, T>();
22 }
23
24 @Override
25 public T lookup(String key) {
26 T cache = this.CONMAP.get(key);
27 if (cache != null) {
28 if ((cache.getCreateTime() + cache.getExpires() - CUTMS) > System
29 .currentTimeMillis()) {
30 return cache;
31 }
32 }
33 return null;
34 }
35
36 @Override
37 public void caching(String key, T cache) {
38 this.CONMAP.put(key, cache);
39 }
40
41 @Override
42 public T evict(String key) {
43 return this.CONMAP.remove(key);
44 }
45
46 @Override
47 public void clear() {
48 this.CONMAP.clear();
49 }
50 }