Package com.gistlabs.mechanize.cache.api

Examples of com.gistlabs.mechanize.cache.api.CacheEntry


    return chain.execute(request, context);
  }

  public HttpResponse executeGET(final HttpUriRequest request, final HttpContext context, final MechanizeFilter chain) {
    String uri = request.getURI().toString();
    CacheEntry previous = cache.get(uri);
    if (previous!=null && previous.isValid())
      return previous.getResponse();

    if (previous!=null)
      previous.prepareConditionalGet(request);

    HttpResponse response = chain.execute(request, context); // call the chain

    if (response.getStatusLine().getStatusCode()==304) // not modified
      return previous.updateCacheValues(response).getResponse();

    CacheEntry maybe = generateCacheEntry(request, response);

    if (maybe.isCacheable())
      store(uri, previous, maybe);

    return response;
  }
View Full Code Here


    return new InMemoryCacheEntry(request, response);
  }

  public HttpResponse executeHEAD(final HttpUriRequest request, final HttpContext context, final MechanizeFilter chain) {
    String uri = request.getURI().toString();
    CacheEntry previous = cache.get(uri);

    if (previous!=null && previous.isValid())
      return previous.head();

    if (previous!=null)
      previous.prepareConditionalGet(request);

    HttpResponse response = chain.execute(request, context); // call the chain

    if (previous!=null)
      previous.updateCacheValues(response);

    return response;
  }
View Full Code Here

    return String.format("InMemoryHttpCache[current=%skb]", currentBytes.get()/1024);
  }

  @Override
  public CacheEntry get(final String uri) {
    CacheEntry entry = cache.get(uri);

    if (entry!=null) { // refresh LRU
      entry.getResponse().setHeader("Via", "mechanize");
      uriFifo.remove(uri);
      uriFifo.offer(uri);
    }

View Full Code Here

    return entry;
  }

  @Override
  public void remove(final String uri) {
    CacheEntry removed = cache.remove(uri);
    uriFifo.remove(uri);

    if (removed!=null)
      currentBytes.addAndGet(-getByteCount(removed));
  }
View Full Code Here

  @Override
  public boolean putIfAbsent(final String uri, final CacheEntry maybe) {
    if (!ensureCapacity(getByteCount(maybe)))
      return false; // and don't cache

    CacheEntry previous = cache.putIfAbsent(uri, maybe);

    currentBytes.addAndGet(getByteCount(maybe) - getByteCount(previous));
    return true;
  }
View Full Code Here

TOP

Related Classes of com.gistlabs.mechanize.cache.api.CacheEntry

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.