You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

20 lines
543 B

import java.util.HashMap;
import java.util.Map;
public class Cache<K, V> {
private final Map<K, V> cache;
public Cache() {
cache = new HashMap<>();
}
public synchronized void put(K key, V value) {
cache.put(key, value);
}
public synchronized V get(K key) {
return cache.get(key);
}
public synchronized boolean hasKey(K key) {
return cache.containsKey(key);
}
public synchronized void remove(K key) {
cache.remove(key);
}
}