Package org.apache.abdera.protocol.client.cache

Examples of org.apache.abdera.protocol.client.cache.Cache


  public Cache getCache() {
    return cache;
  }
 
  public Cache initCache(CacheFactory factory) {
    Cache cache = null;
    if (factory != null) cache = factory.getCache(abdera);
    return (cache != null) ? cache : new LRUCache(abdera);
  }
View Full Code Here


    String uri,
    RequestEntity entity,
    RequestOptions options) {
      try {
        if (options == null) options = getDefaultRequestOptions();
        Cache cache = getCache();
        CacheDisposition disp =
          (useCache(method,options)) ?
            cache.getDisposition(uri, options) :
            CacheDisposition.TRANSPARENT;
        CachedResponse cached_response = cache.get(uri, options);
        disp = (!disp.equals(CacheDisposition.TRANSPARENT) &&
                mustRevalidate(options, cached_response)) ?
                  CacheDisposition.STALE :
                  disp;
        switch(disp) {
          case FRESH:                                                            // CACHE HIT: FRESH
            if (cached_response != null)
              return cached_response;
          case STALE:                                                            // CACHE HIT: STALE
            // revalidate the cached entry
            if (cached_response != null && cached_response.getEntityTag() != null) {
              options.setIfModifiedSince(cached_response.getLastModified());
              options.setIfNoneMatch(cached_response.getEntityTag().toString());
            } else {
              disp = CacheDisposition.TRANSPARENT;
            }
          default:                                                               // CACHE MISS
            HttpMethod httpMethod =
              MethodHelper.createMethod(
                method, uri, entity, options);
            client.executeMethod(httpMethod);
            ClientResponse response = new CommonsResponse(abdera,httpMethod);
            return (options.getUseLocalCache()) ?
              response = cache.update(options, response, cached_response) :
              response;
        }
      } catch (Throwable t) {
        throw new ClientException(t);
      }
View Full Code Here

  public Cache getCache() {
    return cache;
  }
 
  public Cache initCache(CacheFactory factory) {
    Cache cache = null;
    if (factory != null) cache = factory.getCache(abdera);
    return (cache != null) ? cache : new LRUCache(abdera);
  }
View Full Code Here

    RequestOptions options) {
      boolean usecache = useCache(method,options);
      options = options != null ? options : getDefaultRequestOptions();
      HttpMethod httpMethod = null;
      try {
        Cache cache = getCache();
        CachedResponse cached_response = cache.get(uri);
        switch(
          getCacheDisposition(
            usecache,
            uri,
            options,
            cached_response)) {
          case FRESH:                                                            // CACHE HIT: FRESH
            if (cached_response != null)
              return checkRequestException(
                cached_response,options);
          case STALE:                                                            // CACHE HIT: STALE
            // revalidate the cached entry
            if (cached_response != null) {
              if (cached_response.getEntityTag() != null)
                options.setIfNoneMatch(cached_response.getEntityTag().toString());
              else if (cached_response.getLastModified() != null)
                options.setIfModifiedSince(cached_response.getLastModified());
              else options.setNoCache(true);
            }
          default:                                                               // CACHE MISS
            httpMethod =
              MethodHelper.createMethod(
                method, uri, entity, options);
            client.executeMethod(httpMethod);
            if (usecache &&
                (httpMethod.getStatusCode() == 304 ||
                 httpMethod.getStatusCode() == 412) &&
                cached_response != null) return cached_response;
            ClientResponse response = new CommonsResponse(abdera,httpMethod);
            response = options.getUseLocalCache() ?
              response = cache.update(uri, options, response, cached_response) :
              response;
            return checkRequestException(response,options);
        }
      } catch (RuntimeException r) {
        throw r;
View Full Code Here

 
  /**
   * Initializes the client HTTP cache
   */
  public Cache initCache(CacheFactory factory) {
    Cache cache = null;
    if (factory != null) cache = factory.getCache(abdera);
    return (cache != null) ? cache : new LRUCache(abdera);
  }
View Full Code Here

    RequestEntity entity,
    RequestOptions options) {
      boolean usecache = useCache(method,options);
      options = options != null ? options : getDefaultRequestOptions();
      try {
        Cache cache = getCache();
        CachedResponse cached_response = cache.get(uri);
        switch(
          getCacheDisposition(
            usecache,
            uri,
            options,
            cached_response)) {
          case FRESH:                                                            // CACHE HIT: FRESH
            if (cached_response != null)
              return checkRequestException(
                cached_response,options);
          case STALE:                                                            // CACHE HIT: STALE
            // revalidate the cached entry
            if (cached_response != null) {
              if (cached_response.getEntityTag() != null)
                options.setIfNoneMatch(cached_response.getEntityTag().toString());
              else if (cached_response.getLastModified() != null)
                options.setIfModifiedSince(cached_response.getLastModified());
              else options.setNoCache(true);
            }
          default:                                                               // CACHE MISS
            HttpMethod httpMethod =
              MethodHelper.createMethod(
                method, uri, entity, options);
            client.executeMethod(httpMethod);
            if (usecache &&
                (httpMethod.getStatusCode() == 304 ||
                 httpMethod.getStatusCode() == 412) &&
                cached_response != null) return cached_response;
            ClientResponse response = new CommonsResponse(abdera,httpMethod);
            response = options.getUseLocalCache() ?
              response = cache.update(uri, options, response, cached_response) :
              response;
            return checkRequestException(response,options);
        }
      } catch (RuntimeException r) {
        throw r;
View Full Code Here

     */
    public ClientResponse execute(String method, String uri, RequestEntity entity, RequestOptions options) {
        boolean usecache = useCache(method, options);
        options = options != null ? options : getDefaultRequestOptions();
        try {
            Cache cache = getCache();
            CachedResponse cached_response = cache.get(uri);
            switch (getCacheDisposition(usecache, uri, options, cached_response)) {
                case FRESH: // CACHE HIT: FRESH
                    if (cached_response != null)
                        return checkRequestException(cached_response, options);
                case STALE: // CACHE HIT: STALE
                    // revalidate the cached entry
                    if (cached_response != null) {
                        if (cached_response.getEntityTag() != null)
                            options.setIfNoneMatch(cached_response.getEntityTag().toString());
                        else if (cached_response.getLastModified() != null)
                            options.setIfModifiedSince(cached_response.getLastModified());
                        else
                            options.setNoCache(true);
                    }
                default: // CACHE MISS
                    HttpMethod httpMethod = MethodHelper.createMethod(method, uri, entity, options);
                    client.executeMethod(httpMethod);
                    if (usecache && (httpMethod.getStatusCode() == 304 || httpMethod.getStatusCode() == 412)
                        && cached_response != null)
                        return cached_response;
                    ClientResponse response = new CommonsResponse(abdera, httpMethod);
                    response =
                        options.getUseLocalCache() ? response = cache.update(uri, options, response, cached_response)
                            : response;
                    return checkRequestException(response, options);
            }
        } catch (RuntimeException r) {
            throw r;
View Full Code Here

 
  /**
   * Initializes the client HTTP cache
   */
  public Cache initCache(CacheFactory factory) {
    Cache cache = null;
    if (factory != null) cache = factory.getCache(abdera);
    return (cache != null) ? cache : new LRUCache(abdera);
  }
View Full Code Here

    RequestEntity entity,
    RequestOptions options) {
      boolean usecache = useCache(method,options);
      options = options != null ? options : getDefaultRequestOptions();
      try {
        Cache cache = getCache();
        CachedResponse cached_response = cache.get(uri);
        switch(
          getCacheDisposition(
            usecache,
            uri,
            options,
            cached_response)) {
          case FRESH:                                                            // CACHE HIT: FRESH
            if (cached_response != null)
              return checkRequestException(
                cached_response,options);
          case STALE:                                                            // CACHE HIT: STALE
            // revalidate the cached entry
            if (cached_response != null) {
              if (cached_response.getEntityTag() != null)
                options.setIfNoneMatch(cached_response.getEntityTag().toString());
              else if (cached_response.getLastModified() != null)
                options.setIfModifiedSince(cached_response.getLastModified());
              else options.setNoCache(true);
            }
          default:                                                               // CACHE MISS
            HttpMethod httpMethod =
              MethodHelper.createMethod(
                method, uri, entity, options);
            client.executeMethod(httpMethod);
            if (usecache &&
                (httpMethod.getStatusCode() == 304 ||
                 httpMethod.getStatusCode() == 412) &&
                cached_response != null) return cached_response;
            ClientResponse response = new CommonsResponse(abdera,httpMethod);
            response = options.getUseLocalCache() ?
              response = cache.update(uri, options, response, cached_response) :
              response;
            return checkRequestException(response,options);
        }
      } catch (RuntimeException r) {
        throw r;
View Full Code Here

  public Cache getCache() {
    return cache;
  }
 
  public Cache initCache(CacheFactory factory) {
    Cache cache = null;
    if (factory != null) cache = factory.getCache(abdera);
    return (cache != null) ? cache : new LRUCache(abdera);
  }
View Full Code Here

TOP

Related Classes of org.apache.abdera.protocol.client.cache.Cache

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.