LRUCacheStore.java
1.48 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.aemds.guide.cache.impl;
import com.adobe.aemds.guide.cache.CacheObject;
import com.adobe.aemds.guide.cache.api.CacheStore;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class LRUCacheStore
implements CacheStore {
private Logger logger = LoggerFactory.getLogger(LRUCacheStore.class);
private Map<Object, CacheObject> cache;
private int maxEntries;
public LRUCacheStore(int initialCapacity, int entries) {
this.maxEntries = entries;
this.cache = Collections.synchronizedMap(new LinkedHashMap<Object, CacheObject>(initialCapacity + 1, 1.0f, true){
@Override
protected boolean removeEldestEntry(Map.Entry eldest) {
return this.size() > LRUCacheStore.this.maxEntries;
}
});
}
public CacheObject get(Object key) {
return this.cache.get(key);
}
public CacheObject put(Object key, CacheObject value) {
return this.cache.put(key, value);
}
public void clearAll() {
this.cache.clear();
}
public void clear(String key) {
if (this.cache.containsKey(key)) {
this.cache.remove(key);
}
}
public boolean entryExists(Object key) {
return this.cache.containsKey(key);
}
}