org.apache.shindig.gadgets.http
Class AbstractHttpCache

java.lang.Object
  extended by org.apache.shindig.gadgets.http.AbstractHttpCache
All Implemented Interfaces:
HttpCache
Direct Known Subclasses:
DefaultHttpCache

public abstract class AbstractHttpCache
extends Object
implements HttpCache

Base class for content caches. Defines cache expiration rules and and restrictions on allowed content. Implementations that override this are discouraged from using custom cache keys unless there is actually customization in the request object itself. It is highly recommended that you still use createKey(org.apache.shindig.gadgets.http.HttpRequest) in the base class and append any custom data to the end of the key instead of building your own keys from scratch.


Constructor Summary
AbstractHttpCache()
           
 
Method Summary
 boolean addResponse(HttpRequest request, HttpResponse response)
          Add a request/response pair to the cache.
protected abstract  void addResponseImpl(String key, HttpResponse response)
           
 String createKey(HttpRequest request)
          Produce a key from the given request.
protected static String getAppUrl(HttpRequest request)
           
protected static String getInstanceId(HttpRequest request)
           
protected static String getOwnerId(HttpRequest request)
           
 HttpResponse getResponse(HttpRequest request)
           
protected abstract  HttpResponse getResponseImpl(String key)
           
protected static String getServiceName(HttpRequest request)
           
protected static String getTokenName(HttpRequest request)
           
protected static String getTokenOwner(HttpRequest request)
           
protected static String getViewerId(HttpRequest request)
           
protected  boolean isCacheable(HttpRequest request)
           
protected  boolean isCacheable(HttpRequest request, HttpResponse response)
           
 HttpResponse removeResponse(HttpRequest request)
           
protected abstract  HttpResponse removeResponseImpl(String key)
           
protected  boolean responseStillUsable(HttpResponse response)
          Utility function to verify that an entry is usable The cache still serve staled data, it is the responsible of the user to decide if to use it or not (use isStale).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractHttpCache

public AbstractHttpCache()
Method Detail

getResponseImpl

protected abstract HttpResponse getResponseImpl(String key)

addResponseImpl

protected abstract void addResponseImpl(String key,
                                        HttpResponse response)

removeResponseImpl

protected abstract HttpResponse removeResponseImpl(String key)

getResponse

public final HttpResponse getResponse(HttpRequest request)
Specified by:
getResponse in interface HttpCache

addResponse

public boolean addResponse(HttpRequest request,
                           HttpResponse response)
Description copied from interface: HttpCache
Add a request/response pair to the cache.

Specified by:
addResponse in interface HttpCache
Returns:
true if the response was cached, false if the response was not cached.

removeResponse

public HttpResponse removeResponse(HttpRequest request)
Specified by:
removeResponse in interface HttpCache

isCacheable

protected boolean isCacheable(HttpRequest request)

isCacheable

protected boolean isCacheable(HttpRequest request,
                              HttpResponse response)

createKey

public String createKey(HttpRequest request)
Produce a key from the given request. Relevant pieces of the cache key: - request URI - authentication type - owner id - viewer id - owner of the token - gadget url (from security token; we don't trust what's on the URI itself) - instance id - oauth service name - oauth token name - the resize height parameter - the resize width parameter - the resize quality parameter Except for the first two, all of these may be unset or null, depending on authentication rules. See individual methods for details. New cache key items should always be inserted using CacheKeyBuilder#setParam(String, Object).

Specified by:
createKey in interface HttpCache

getOwnerId

protected static String getOwnerId(HttpRequest request)

getViewerId

protected static String getViewerId(HttpRequest request)

getTokenOwner

protected static String getTokenOwner(HttpRequest request)

getAppUrl

protected static String getAppUrl(HttpRequest request)

getInstanceId

protected static String getInstanceId(HttpRequest request)

getServiceName

protected static String getServiceName(HttpRequest request)

getTokenName

protected static String getTokenName(HttpRequest request)

responseStillUsable

protected boolean responseStillUsable(HttpResponse response)
Utility function to verify that an entry is usable The cache still serve staled data, it is the responsible of the user to decide if to use it or not (use isStale).

Returns:
true If the response can be used.


Copyright © 2007-2012. All Rights Reserved.