Cache value now has convenience constructor.
Implemented the changes. Also placed putting data in hashmap priority so for faster access.
This commit is contained in:
parent
3e80d1e67d
commit
9b111cc977
@ -32,11 +32,9 @@ public class Cache<K, V> {
|
||||
lock.lock();
|
||||
try {
|
||||
if (data.containsKey(key)) return;
|
||||
CacheValue<K, V> val = new CacheValue<>();
|
||||
val.key = key;
|
||||
val.value = value;
|
||||
usage.add(val);
|
||||
CacheValue<K, V> val = new CacheValue<>(key, value);
|
||||
data.put(key, val);
|
||||
usage.add(val);
|
||||
if (data.size() > maxSize) {
|
||||
data.remove(usage.pop().key);
|
||||
}
|
||||
|
@ -21,4 +21,9 @@ class CacheValue<KeyType, ValueType> {
|
||||
*/
|
||||
public volatile boolean detached = true;
|
||||
|
||||
public CacheValue(KeyType key, ValueType value) {
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user