Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

com.opencms.flex.cache
Class CmsFlexCacheEntry  view CmsFlexCacheEntry download CmsFlexCacheEntry.java

java.lang.Object
  extended bycom.opencms.flex.cache.CmsFlexCacheEntry
All Implemented Interfaces:
com.opencms.flex.util.I_CmsFlexLruCacheObject

public class CmsFlexCacheEntry
extends java.lang.Object
implements com.opencms.flex.util.I_CmsFlexLruCacheObject

Contains the contents of a cached resource.

It is basically a list of pre-generated output, include() calls to other resources (with request parameters) and http headers that this resource requires to be set.

A CmsFlexCacheEntry might also describe a redirect-call, but in this case nothing else will be cached.

The pre-generated output is saved in byte[] arrays. The include() calls are saved as Strings of the included resource name, the parameters for the calls are saved in a HashMap. The headers are saved in a HashMap. In case of a redirect, the redircet target is cached in a String.

The CmsFlexCacheEntry can also have a timeout value, which indicates the time that his entry will become invalid and should thus be cleared from the cache.

Version:
$Revision: 1.9.2.1 $

Field Summary
static int C_INITIAL_CAPACITY_LISTS
          Initial size for lists
private static int DEBUG
          Debug switch
private  int ID
          The internal ID of this cache entry.
private static int ID_COUNTER
          Static counter to give each entry a unique ID.
private  int m_byteSize
          The CacheEntry's size in kBytes
private  boolean m_completed
          Indicates if this cache entry is completed
private  java.util.List m_elements
          The list of items for this resource
private  java.util.Map m_headers
          A Map of cached headers for this resource
private  com.opencms.flex.util.I_CmsFlexLruCacheObject m_Next
          Pointer to the next cache entry in the LRU cache
private  com.opencms.flex.util.I_CmsFlexLruCacheObject m_Previous
          Pointer to the previous cache entry in the LRU cache.
private  java.lang.String m_redirectTarget
          A redirection target (if redirection is set)
private  long m_timeout
          Age for timeout
private  java.lang.String m_VariationKey
          The key under which this cache entry is stored in the variation map.
private  java.util.Map m_VariationMap
          The variation map where this cache entry is stored.
 
Constructor Summary
CmsFlexCacheEntry()
          Constructor for class CmsFlexCacheEntry.
 
Method Summary
 void add(byte[] bytes)
          Adds an array of bytes to this cache entry, this will usually be the result of some kind of output - stream.
 void add(java.lang.String resource, java.util.Map paramters)
          Add an include - call target resource to this cache entry.
 void addHeaders(java.util.Map headers)
          Add a map of headers to this cache entry, which are usually collected in the class CmsFlexResponse first.
 void addToLruCache()
          Invoked after an object was added to the cache.
private  void clear()
          Clears the elements and headers HashMaps.
 void complete()
          Completes this cache entry.
 java.util.List elements()
          Returns the list of data entries of this cache entry.
protected  void finalize()
          Finalize this instance.
 int getLruCacheCosts()
          Returns the cache costs of this object, as for example it's byte size.
 com.opencms.flex.util.I_CmsFlexLruCacheObject getNextLruObject()
          Returns the next object in the double linked list of all cached objects.
 com.opencms.flex.util.I_CmsFlexLruCacheObject getPreviousLruObject()
          Returns the previous object in the double linked list of all cached objects.
 long getTimeout()
          Returns the timeout - value of this cache entry, this is set to the time when the entry becomes invalid.
 void removeFromLruCache()
          Invoked after the object was removed to the cache.
 void service(CmsFlexRequest req, CmsFlexResponse res)
          Processing method for this cached entry.
 void setNextLruObject(com.opencms.flex.util.I_CmsFlexLruCacheObject theNextEntry)
          Set the next object in the double linked list of all cached objects.
 void setPreviousLruObject(com.opencms.flex.util.I_CmsFlexLruCacheObject thePreviousEntry)
          Set the previous object in the double linked list of all cached objects.
 void setRedirect(java.lang.String target)
          Set a redirect target for this cache entry.
 void setTimeout(long timeout)
          Sets a timeout value to this cache entry, which indicates the time this entry becomes invalid.
 void setVariationData(java.lang.String theVariationKey, java.util.Map theVariationMap)
          Stores a backward reference to the map and key where this cache entry is stored.
 java.lang.String toString()
          Convert this Object to a human-readable String.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

C_INITIAL_CAPACITY_LISTS

public static final int C_INITIAL_CAPACITY_LISTS
Initial size for lists

See Also:
Constant Field Values

m_elements

private java.util.List m_elements
The list of items for this resource


m_headers

private java.util.Map m_headers
A Map of cached headers for this resource


m_redirectTarget

private java.lang.String m_redirectTarget
A redirection target (if redirection is set)


DEBUG

private static final int DEBUG
Debug switch

See Also:
Constant Field Values

m_timeout

private long m_timeout
Age for timeout


m_completed

private boolean m_completed
Indicates if this cache entry is completed


m_byteSize

private int m_byteSize
The CacheEntry's size in kBytes


m_Next

private com.opencms.flex.util.I_CmsFlexLruCacheObject m_Next
Pointer to the next cache entry in the LRU cache


m_Previous

private com.opencms.flex.util.I_CmsFlexLruCacheObject m_Previous
Pointer to the previous cache entry in the LRU cache.


m_VariationMap

private java.util.Map m_VariationMap
The variation map where this cache entry is stored.


m_VariationKey

private java.lang.String m_VariationKey
The key under which this cache entry is stored in the variation map.


ID_COUNTER

private static int ID_COUNTER
Static counter to give each entry a unique ID.


ID

private int ID
The internal ID of this cache entry.

Constructor Detail

CmsFlexCacheEntry

public CmsFlexCacheEntry()
Constructor for class CmsFlexCacheEntry.

The way to use this class is to first use this empty constructor and later add data with the various add methods.

Method Detail

add

public void add(byte[] bytes)
Adds an array of bytes to this cache entry, this will usually be the result of some kind of output - stream.


add

public void add(java.lang.String resource,
                java.util.Map paramters)
Add an include - call target resource to this cache entry.


addHeaders

public void addHeaders(java.util.Map headers)
Add a map of headers to this cache entry, which are usually collected in the class CmsFlexResponse first.


setRedirect

public void setRedirect(java.lang.String target)
Set a redirect target for this cache entry.

Important: When a redirect target is set, all saved data is thrown away, and new data will not be saved in the cache entry. This is so since with a redirect nothing will be displayed in the browser anyway, so there is no point in saving the data.


elements

public java.util.List elements()
Returns the list of data entries of this cache entry.

Data entries are byte arrays representing some kind of ouput or Strings representing include calls to other resources.


service

public void service(CmsFlexRequest req,
                    CmsFlexResponse res)
             throws com.opencms.core.CmsException,
                    javax.servlet.ServletException,
                    java.io.IOException
Processing method for this cached entry.

If this method is called, it delivers the contents of the cached entry to the given request / response. This includes calls to all included resources.


getTimeout

public long getTimeout()
Returns the timeout - value of this cache entry, this is set to the time when the entry becomes invalid.


setTimeout

public void setTimeout(long timeout)
Sets a timeout value to this cache entry, which indicates the time this entry becomes invalid.

The timeout parameter represents the minute - intervall in which the cache entry is to be cleared. The intervall always starts at 0.00h. A value of 60 would indicate that this entry will reach it's timeout at the beginning of the next full hour, a timeout of 20 would indicate that the entry is invalidated at x.00, x.20 and x.40 of every hour etc.


complete

public void complete()
Completes this cache entry.

A completed cache entry is made "unmodifiable", so that no further data can be added and existing data can not be changed. This is to prevend the (unlikley) case that some user-written class tries to make changes to a cache entry.


toString

public java.lang.String toString()
Description copied from class: java.lang.Object
Convert this Object to a human-readable String. There are no limits placed on how long this String should be or what it should contain. We suggest you make it as intuitive as possible to be able to place it into System.out.println() 55 and such.

It is typical, but not required, to ensure that this method never completes abruptly with a java.lang.RuntimeException.

This method will be called when performing string concatenation with this object. If the result is null, string concatenation will instead use "null".

The default implementation returns getClass().getName() + "@" + Integer.toHexString(hashCode()).


setVariationData

public void setVariationData(java.lang.String theVariationKey,
                             java.util.Map theVariationMap)
Stores a backward reference to the map and key where this cache entry is stored. This is required for the FlexCache.


setNextLruObject

public void setNextLruObject(com.opencms.flex.util.I_CmsFlexLruCacheObject theNextEntry)
Description copied from interface: com.opencms.flex.util.I_CmsFlexLruCacheObject
Set the next object in the double linked list of all cached objects.

Specified by:
setNextLruObject in interface com.opencms.flex.util.I_CmsFlexLruCacheObject

getNextLruObject

public com.opencms.flex.util.I_CmsFlexLruCacheObject getNextLruObject()
Description copied from interface: com.opencms.flex.util.I_CmsFlexLruCacheObject
Returns the next object in the double linked list of all cached objects.

Specified by:
getNextLruObject in interface com.opencms.flex.util.I_CmsFlexLruCacheObject

setPreviousLruObject

public void setPreviousLruObject(com.opencms.flex.util.I_CmsFlexLruCacheObject thePreviousEntry)
Description copied from interface: com.opencms.flex.util.I_CmsFlexLruCacheObject
Set the previous object in the double linked list of all cached objects.

Specified by:
setPreviousLruObject in interface com.opencms.flex.util.I_CmsFlexLruCacheObject

getPreviousLruObject

public com.opencms.flex.util.I_CmsFlexLruCacheObject getPreviousLruObject()
Description copied from interface: com.opencms.flex.util.I_CmsFlexLruCacheObject
Returns the previous object in the double linked list of all cached objects.

Specified by:
getPreviousLruObject in interface com.opencms.flex.util.I_CmsFlexLruCacheObject

addToLruCache

public void addToLruCache()
Description copied from interface: com.opencms.flex.util.I_CmsFlexLruCacheObject
Invoked after an object was added to the cache.

Specified by:
addToLruCache in interface com.opencms.flex.util.I_CmsFlexLruCacheObject

removeFromLruCache

public void removeFromLruCache()
Description copied from interface: com.opencms.flex.util.I_CmsFlexLruCacheObject
Invoked after the object was removed to the cache.

Specified by:
removeFromLruCache in interface com.opencms.flex.util.I_CmsFlexLruCacheObject

getLruCacheCosts

public int getLruCacheCosts()
Description copied from interface: com.opencms.flex.util.I_CmsFlexLruCacheObject
Returns the cache costs of this object, as for example it's byte size.

Specified by:
getLruCacheCosts in interface com.opencms.flex.util.I_CmsFlexLruCacheObject

finalize

protected void finalize()
                 throws java.lang.Throwable
Finalize this instance.


clear

private void clear()
Clears the elements and headers HashMaps.