Skip to content

Instantly share code, notes, and snippets.

@sw-samuraj
Last active September 18, 2017 08:55
Show Gist options
  • Save sw-samuraj/c02d9967a46dfcddd909f9ab1cb8d8b5 to your computer and use it in GitHub Desktop.
Save sw-samuraj/c02d9967a46dfcddd909f9ab1cb8d8b5 to your computer and use it in GitHub Desktop.
public class ObservableCache extends Observable {
private Map<String, PersonInfo> cache = new HashMap<>();
public void put(String key, PersonInfo person) {
cache.put(key, person);
setChanged();
notifyObservers();
}
public boolean containsKey(String key) {
return cache.containsKey(key);
}
public PersonInfo get(String key) {
return cache.get(key);
}
public PersonInfo remove(String key) {
PersonInfo person = cache.remove(key);
setChanged();
notifyObservers();
return person;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment