All Downloads are FREE. Search and download functionalities are using the official Maven repository.

enterprises.orbital.impl.evexmlapi.CachingConnector Maven / Gradle / Ivy

There is a newer version: 2.4.0
Show newest version
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();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy