com.caucho.portal.generic
Class Cache

java.lang.Object
  extended by com.caucho.portal.generic.Cache

public abstract class Cache
extends java.lang.Object


Field Summary
protected static java.util.logging.Logger log
           
 
Constructor Summary
Cache()
           
 
Method Summary
abstract  void finishCaching(java.io.OutputStream outputStream, int expirationCache, CacheKey cacheKey, java.util.Map<java.lang.String,java.lang.Object> cachePropertiesMap, java.util.Map<java.lang.String,java.lang.Object> propertiesMap, java.util.Map<java.lang.String,java.lang.String> requestAttributeMap)
          Finish with an OutputStream previously returned by #startCachingOutputStream.
abstract  void finishCaching(java.io.Writer writer, int expirationCache, CacheKey cacheKey, java.lang.String encoding, java.util.Map<java.lang.String,java.lang.Object> cachePropertiesMap, java.util.Map<java.lang.String,java.lang.Object> propertiesMap, java.util.Map<java.lang.String,java.lang.String> requestAttributeMap)
          Finish with a Writer previously returned by #startCachingWriter.
abstract  java.io.OutputStream getCachingOutputStream(java.lang.String namespace, int expirationCache, boolean isPrivate)
          Called immediately before a Portlet is rendered to give the Cache an opportunity to cache the response.
abstract  java.io.Writer getCachingWriter(java.lang.String namespace, int expirationCache, boolean isPrivate)
          Called to give the Cache an opportunity to cache the response.
abstract  int respondFromCache(CacheKey cacheKey, RenderRequest request, RenderResponse response)
          Send a response from the cache, or return false if there is no response from the cache.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static final java.util.logging.Logger log
Constructor Detail

Cache

public Cache()
Method Detail

respondFromCache

public abstract int respondFromCache(CacheKey cacheKey,
                                     RenderRequest request,
                                     RenderResponse response)
Send a response from the cache, or return false if there is no response from the cache. The passed cacheKey can be manipulated by the cache without side-effects, but the cache cannot take ownership of the cacheKey because it may be pooled by the caller. Binary responses should be sent to the OutputStream obtained with response.getOutputStream(). Textual response should be sent to the PrintWriter obtained with response.getWriter(). response.setCharacterEncoding() should be used before getWriter() to set the character encoding to the character encoding that was in use when the response was cached. If isPrivate is true, then cacheKey.getRequestedSessionId() will have a non-null value. A cache should first perform a lookup with the CacheKey as provided. If that fails, it should call cacheKey.setLocale(null) and try again. The cache should also check the value of cacheKey.getContentType(). If the contentType is null, the cache can respond if it has an entry that matches for one contentType. If a match is found, the cache sets the contentType with connection.setContentType().

Returns:
0 if no response was written from the cache, otherwise the number of seconds that a response written from the cache is good for or -1 if the cached reponse is good forever

getCachingWriter

public abstract java.io.Writer getCachingWriter(java.lang.String namespace,
                                                int expirationCache,
                                                boolean isPrivate)
                                         throws java.io.IOException
Called to give the Cache an opportunity to cache the response. If the response can be cached, the implementation returns a Writer that receives the response. When the response is completed, finishCaching(Writer) will be called. If the response cannot be cached, the implementation returns null. At this point, the expirationCache is a best guess and the real value passed to finishCaching() may be different.

Parameters:
window - the portlet configuration for the portlet about to be rendered
namespace - the namespace for the portlet about to be rendered
expirationCache - a best guess at the expiration period in seconds, -1 if unlimited
Returns:
a Writer that intercepts the content and then writes to response.getWriter(), or null if the response cannot be cached.
Throws:
java.io.IOException

getCachingOutputStream

public abstract java.io.OutputStream getCachingOutputStream(java.lang.String namespace,
                                                            int expirationCache,
                                                            boolean isPrivate)
                                                     throws java.io.IOException
Called immediately before a Portlet is rendered to give the Cache an opportunity to cache the response. If the response can be cached, the implementation returns an OutputStream that receives the response. When the response is completed, finishCaching(OutputStream) will be called. If the response cannot be cached, the implementation returns null. At this point, the expirationCache is a best guess and the real value passed to finishCaching() may be different.

Parameters:
window - the portlet window for the portlet about to be rendered
namespace - the namespace for the portlet about to be rendered
expirationCache - a best guess at the expiration period in seconds, -1 if unlimited
Returns:
an OutputStream that intercepts the content and then writes to response.getOutputStream(), or null if the response cannot be cached.
Throws:
java.io.IOException

finishCaching

public abstract void finishCaching(java.io.Writer writer,
                                   int expirationCache,
                                   CacheKey cacheKey,
                                   java.lang.String encoding,
                                   java.util.Map<java.lang.String,java.lang.Object> cachePropertiesMap,
                                   java.util.Map<java.lang.String,java.lang.Object> propertiesMap,
                                   java.util.Map<java.lang.String,java.lang.String> requestAttributeMap)
Finish with a Writer previously returned by #startCachingWriter. If the expirationCache is 0 or the cacheKey is null, the cached response must be discarded.

Parameters:
writer - the writer returned from #startCachingWriter
expirationCache - the updated expirationCache, this may the same value received in #startWriter, a new value set by the portlet while it rendered itself, or 0 if the cache must be discarded.
cacheKey - the CacheKey that uniquely differentiates this response from other responses
encoding - the encoding for the Writer, the cache needs to call response.setEncoding(encoding) if it later responds in respondFromCache().
cachePropertiesMap - a map of properties that begin with "Cache-", these may be directives to the cache or may be keys and values that should distinguish the uniqueness of the Cached value beyond the uniqueness established by CacheKey, depending on the portal implementation. These properties should be recreated during respondFromCache(). If the value is a String, setProperty is used. If the value is an ArrayList, add property is used.
propertiesMap - a map of properties that the Cache must recreate when the cached response is used in a susbsequent call to respondFromCache If the value is a String, setProperty is used. If the value is an ArrayList, add property is used.
requestAttributesMap - a map of request attributes that the Cache must recreate when the cached response is used in a susbsequent call to respondFromCache

finishCaching

public abstract void finishCaching(java.io.OutputStream outputStream,
                                   int expirationCache,
                                   CacheKey cacheKey,
                                   java.util.Map<java.lang.String,java.lang.Object> cachePropertiesMap,
                                   java.util.Map<java.lang.String,java.lang.Object> propertiesMap,
                                   java.util.Map<java.lang.String,java.lang.String> requestAttributeMap)
Finish with an OutputStream previously returned by #startCachingOutputStream. If the cacheKey is null or the expirationCache is 0, the cached response must be discarded.