org.snapscript.common.LeastRecentlyUsedCache Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of snap Show documentation
Show all versions of snap Show documentation
Dynamic scripting for the JVM
package org.snapscript.common;
import java.util.Map;
import java.util.Set;
import org.snapscript.common.LeastRecentlyUsedMap.RemovalListener;
public class LeastRecentlyUsedCache implements Cache {
private final Map cache;
public LeastRecentlyUsedCache() {
this(null);
}
public LeastRecentlyUsedCache(int capacity) {
this(null, capacity);
}
public LeastRecentlyUsedCache(RemovalListener removalListener) {
this(removalListener, 100);
}
public LeastRecentlyUsedCache(RemovalListener removalListener, int capacity) {
this.cache = new LeastRecentlyUsedMap(removalListener, capacity);
}
@Override
public synchronized void clear() {
cache.clear();
}
@Override
public synchronized int size() {
return cache.size();
}
@Override
public synchronized Set keySet() {
return cache.keySet();
}
@Override
public synchronized V fetch(K key) {
return cache.get(key);
}
@Override
public synchronized void cache(K key, V value) {
cache.put(key, value);
}
@Override
public synchronized V take(K key) {
return cache.remove(key);
}
@Override
public synchronized boolean contains(K key) {
return cache.containsKey(key);
}
@Override
public synchronized boolean isEmpty() {
return cache.isEmpty();
}
}