enterprises.orbital.impl.evexmlapi.CachingConnector Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of eve-xml-api Show documentation
Show all versions of eve-xml-api Show documentation
Library to interact with EVE XML API servers
package enterprises.orbital.impl.evexmlapi;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.digester.Digester;
/**
* Connector which caches the results of previous requests.
*/
public class CachingConnector extends ApiConnector {
private final Map cache = new HashMap();
private final ApiConnector baseConnector;
public CachingConnector() {
this.baseConnector = null;
}
public CachingConnector(ApiConnector baseConnector) {
this.baseConnector = baseConnector;
}
@SuppressWarnings("unchecked")
@Override
public E execute(ApiRequest request, Digester digester, Class clazz) throws IOException {
if (!cache.containsKey(request)) cache.put(request, getConnector().execute(request, digester, clazz));
return (E) cache.get(request);
}
@Override
protected ApiConnector getConnector() {
if (baseConnector != null) return baseConnector;
return super.getConnector();
}
}