PayloadCache.java [src/csip/utils] Revision: Date:
package csip.utils;
import csip.ModelDataServiceConstants;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
/**
* PayloadCache
*
* @author od
*/
public class PayloadCache {
LRUCache<Integer, JSONObject> cache = new LRUCache<>();
public PayloadCache withSize(int size) {
cache.setSize(size);
return this;
}
public JSONObject getResult(JSONArray param) {
JSONObject o = cache.get(param.hashCode());
if (o != null) {
try {
o.getJSONObject(ModelDataServiceConstants.KEY_METAINFO)
.put("cache", true);
} catch (JSONException E) {
System.err.println(E);
}
}
return o;
}
public void putResult(JSONArray param, JSONObject result) {
cache.put(param.hashCode(), result);
}
public void clear() {
cache.clear();
}
}