package com.sap.jod.test.protobuf;
import java.util.Collections;
import javax.cache.Cache;
import javax.cache.CacheException;
import javax.cache.CacheManager;
import com.sap.jod.test.protobuf.UserStoreProtos.User;
public class CacheHandler {
private static CacheHandler instance = null;
public static CacheHandler getInstance() {
if (instance==null) {
instance = new CacheHandler();
instance.initCache();
}
return instance;
}
private Cache cache;
private void initCache() {
try {
cache = CacheManager.getInstance().getCacheFactory().createCache(Collections.emptyMap());
} catch (CacheException e) {
throw new RuntimeException(e);
}
}
public void clearCache() {
cache.clear();
}
public byte[] get(String key) {
return (byte[]) cache.get(key);
}
public void put(String key, byte[] data) {
cache.put(key, data);
}
public String getString(String key) {
return (String) cache.get(key);
}
public void putString(String key, String user) {
cache.put(key, user);
}
}
|