com.clickntap.tool.cache.MemoryCache Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of Stripecube Show documentation
Show all versions of Stripecube Show documentation
Stripecube is an open source Java framework for Web Applications
package com.clickntap.tool.cache;
import java.io.Serializable;
public class MemoryCache implements Cache {
private MemoryLruMap memory;
public MemoryCache() {
memory = new MemoryLruMap(999999);
}
public Serializable get(Serializable key) throws Exception {
synchronized (memory) {
return memory.get(key);
}
}
public Serializable put(Serializable key, Serializable value) throws Exception {
if (contains(key))
return value;
synchronized (memory) {
return memory.put(key, value);
}
}
public void remove(Serializable key) throws Exception {
synchronized (memory) {
memory.remove(key);
}
}
public void removeAll() throws Exception {
synchronized (memory) {
memory.clear();
}
}
public boolean contains(Serializable key) throws Exception {
synchronized (memory) {
return memory.containsKey(key);
}
}
}