Class CmsFlexCacheEntry
- java.lang.Object
-
- org.opencms.flex.CmsFlexCacheEntry
-
- All Implemented Interfaces:
I_CmsLruCacheObject
,I_CmsMemoryMonitorable
public class CmsFlexCacheEntry extends java.lang.Object implements I_CmsLruCacheObject, I_CmsMemoryMonitorable
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 redirect target is cached in a String.The CmsFlexCacheEntry can also have an expire date value, which indicates the time that his entry will become invalid and should thus be cleared from the cache.
- Since:
- 6.0.0
- See Also:
I_CmsLruCacheObject
-
-
Field Summary
Fields Modifier and Type Field Description static int
INITIAL_CAPACITY_LISTS
Initial size for lists.
-
Constructor Summary
Constructors Constructor Description CmsFlexCacheEntry()
Constructor for class CmsFlexCacheEntry.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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<java.lang.String,java.lang.String[]> parameters, java.util.Map<java.lang.String,java.lang.Object> attrs)
Add an include - call target resource to this cache entry.void
addHeaders(java.util.Map<java.lang.String,java.util.List<java.lang.String>> 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.void
complete()
Completes this cache entry.java.util.List<java.lang.Object>
elements()
Returns the list of data entries of this cache entry.CmsFlexBucketConfiguration.BucketSet
getBucketSet()
Gets the bucket set for this flex cache entry (may be null).long
getDateExpires()
Returns the expiration date of this cache entry, this is set to the time when the entry becomes invalid.long
getDateLastModified()
Returns the "last modified" date for this Flex cache entry.int
getLruCacheCosts()
Returns the cache costs of this object, as for example it's byte size.int
getMemorySize()
Returns the memory size of the object.I_CmsLruCacheObject
getNextLruObject()
Returns the next object in the double linked list of all cached objects.I_CmsLruCacheObject
getPreviousLruObject()
Returns the previous object in the double linked list of all cached objects.java.lang.Object
getValue()
Returns the Object value.void
limitDateExpires(long limit)
Ensures that the expiration date is at most 'limit'.void
removeFromLruCache()
Invoked after the object was removed to the cache.void
service(CmsFlexRequest req, CmsFlexResponse res)
Processing method for this cached entry.void
setBucketSet(CmsFlexBucketConfiguration.BucketSet bucketSet)
Sets the bucket set for this flex cache entry.void
setDateExpires(long dateExpires)
Sets the expiration date of this Flex cache entry exactly to the given time.void
setDateExpiresToNextTimeout(long timeout)
Sets an expiration date for this cache entry to the next timeout, which indicates the time this entry becomes invalid.void
setDateLastModified(long dateLastModified)
Sets the "last modified" date for this Flex cache entry with the given value.void
setDateLastModifiedToPreviousTimeout(long timeout)
Sets the "last modified" date for this Flex cache entry by using the last passed timeout value.void
setNextLruObject(I_CmsLruCacheObject theNextEntry)
Set the next object in the double linked list of all cached objects.void
setPreviousLruObject(I_CmsLruCacheObject thePreviousEntry)
Set the previous object in the double linked list of all cached objects.void
setRedirect(java.lang.String target, boolean permanent)
Set a redirect target for this cache entry.void
setVariationData(java.lang.String theVariationKey, java.util.Map<java.lang.String,I_CmsLruCacheObject> theVariationMap)
Stores a backward reference to the map and key where this cache entry is stored.java.lang.String
toString()
-
-
-
Field Detail
-
INITIAL_CAPACITY_LISTS
public static final int INITIAL_CAPACITY_LISTS
Initial size for lists.- See Also:
- Constant Field Values
-
-
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.- Parameters:
bytes
- the output to save in the cache
-
add
public void add(java.lang.String resource, java.util.Map<java.lang.String,java.lang.String[]> parameters, java.util.Map<java.lang.String,java.lang.Object> attrs)
Add an include - call target resource to this cache entry.- Parameters:
resource
- a name of a resource in the OpenCms VFSparameters
- a map of parameters specific to this include callattrs
- a map of request attributes specific to this include call
-
addHeaders
public void addHeaders(java.util.Map<java.lang.String,java.util.List<java.lang.String>> headers)
Add a map of headers to this cache entry, which are usually collected in the class CmsFlexResponse first.- Parameters:
headers
- the map of headers to add to the entry
-
addToLruCache
public void addToLruCache()
Description copied from interface:I_CmsLruCacheObject
Invoked after an object was added to the cache.- Specified by:
addToLruCache
in interfaceI_CmsLruCacheObject
- See Also:
I_CmsLruCacheObject.addToLruCache()
-
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 prevent the (unlikely) case that some user-written class tries to make changes to a cache entry.
-
elements
public java.util.List<java.lang.Object> elements()
Returns the list of data entries of this cache entry.Data entries are byte arrays representing some kind of output or Strings representing include calls to other resources.
- Returns:
- the list of data elements of this cache entry
-
getBucketSet
public CmsFlexBucketConfiguration.BucketSet getBucketSet()
Gets the bucket set for this flex cache entry (may be null).- Returns:
- the bucket set for this flex cache entry
-
getDateExpires
public long getDateExpires()
Returns the expiration date of this cache entry, this is set to the time when the entry becomes invalid.- Returns:
- the expiration date value for this resource
-
getDateLastModified
public long getDateLastModified()
Returns the "last modified" date for this Flex cache entry.- Returns:
- the "last modified" date for this Flex cache entry
-
getLruCacheCosts
public int getLruCacheCosts()
Description copied from interface:I_CmsLruCacheObject
Returns the cache costs of this object, as for example it's byte size.- Specified by:
getLruCacheCosts
in interfaceI_CmsLruCacheObject
- Returns:
- the cache costs of this object
- See Also:
I_CmsLruCacheObject.getLruCacheCosts()
-
getMemorySize
public int getMemorySize()
Description copied from interface:I_CmsMemoryMonitorable
Returns the memory size of the object.- Specified by:
getMemorySize
in interfaceI_CmsMemoryMonitorable
- Returns:
- the memory size of the object
- See Also:
I_CmsMemoryMonitorable.getMemorySize()
-
getNextLruObject
public I_CmsLruCacheObject getNextLruObject()
Description copied from interface:I_CmsLruCacheObject
Returns the next object in the double linked list of all cached objects.- Specified by:
getNextLruObject
in interfaceI_CmsLruCacheObject
- Returns:
- the next object in the double linked list of all cached objects
- See Also:
I_CmsLruCacheObject.getNextLruObject()
-
getPreviousLruObject
public I_CmsLruCacheObject getPreviousLruObject()
Description copied from interface:I_CmsLruCacheObject
Returns the previous object in the double linked list of all cached objects.- Specified by:
getPreviousLruObject
in interfaceI_CmsLruCacheObject
- Returns:
- the previous object in the double linked list of all cached objects
- See Also:
I_CmsLruCacheObject.getPreviousLruObject()
-
getValue
public java.lang.Object getValue()
Description copied from interface:I_CmsLruCacheObject
Returns the Object value.- Specified by:
getValue
in interfaceI_CmsLruCacheObject
- Returns:
- the Object value
- See Also:
I_CmsLruCacheObject.getValue()
-
limitDateExpires
public void limitDateExpires(long limit)
Ensures that the expiration date is at most 'limit'.- Parameters:
limit
- the maximum allowed expiration date
-
removeFromLruCache
public void removeFromLruCache()
Description copied from interface:I_CmsLruCacheObject
Invoked after the object was removed to the cache.- Specified by:
removeFromLruCache
in interfaceI_CmsLruCacheObject
- See Also:
I_CmsLruCacheObject.removeFromLruCache()
-
service
public void service(CmsFlexRequest req, CmsFlexResponse res) throws CmsFlexCacheException, 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.
- Parameters:
req
- the request from the clientres
- the server response- Throws:
CmsFlexCacheException
- is thrown when problems writing to the response output-stream occurjavax.servlet.ServletException
- might be thrown from call to RequestDispatcher.include()java.io.IOException
- might be thrown from call to RequestDispatcher.include() or from Response.sendRedirect()
-
setBucketSet
public void setBucketSet(CmsFlexBucketConfiguration.BucketSet bucketSet)
Sets the bucket set for this flex cache entry.- Parameters:
bucketSet
- the bucket set to set
-
setDateExpires
public void setDateExpires(long dateExpires)
Sets the expiration date of this Flex cache entry exactly to the given time.- Parameters:
dateExpires
- the time to expire this cache entry
-
setDateExpiresToNextTimeout
public void setDateExpiresToNextTimeout(long timeout)
Sets an expiration date for this cache entry to the next timeout, which indicates the time this entry becomes invalid.The timeout parameter represents the minute - interval in which the cache entry is to be cleared. The interval always starts at 0.00h. A value of 60 would indicate that this entry will reach it's expiration date 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.
- Parameters:
timeout
- the timeout value to be set
-
setDateLastModified
public void setDateLastModified(long dateLastModified)
Sets the "last modified" date for this Flex cache entry with the given value.- Parameters:
dateLastModified
- the value to set for the "last modified" date
-
setDateLastModifiedToPreviousTimeout
public void setDateLastModifiedToPreviousTimeout(long timeout)
Sets the "last modified" date for this Flex cache entry by using the last passed timeout value.If a cache entry uses the timeout feature, it becomes invalid every time the timeout interval passes. Thus the "last modified" date is the time the last timeout passed.
- Parameters:
timeout
- the timeout value to use to calculate the date last modified
-
setNextLruObject
public void setNextLruObject(I_CmsLruCacheObject theNextEntry)
Description copied from interface:I_CmsLruCacheObject
Set the next object in the double linked list of all cached objects.- Specified by:
setNextLruObject
in interfaceI_CmsLruCacheObject
- Parameters:
theNextEntry
- the next object- See Also:
I_CmsLruCacheObject.setNextLruObject(org.opencms.cache.I_CmsLruCacheObject)
-
setPreviousLruObject
public void setPreviousLruObject(I_CmsLruCacheObject thePreviousEntry)
Description copied from interface:I_CmsLruCacheObject
Set the previous object in the double linked list of all cached objects.- Specified by:
setPreviousLruObject
in interfaceI_CmsLruCacheObject
- Parameters:
thePreviousEntry
- the previous object- See Also:
I_CmsLruCacheObject.setPreviousLruObject(org.opencms.cache.I_CmsLruCacheObject)
-
setRedirect
public void setRedirect(java.lang.String target, boolean permanent)
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.
- Parameters:
target
- The redirect target (must be a valid URL).permanent
- true if this is a permanent redirect
-
setVariationData
public void setVariationData(java.lang.String theVariationKey, java.util.Map<java.lang.String,I_CmsLruCacheObject> theVariationMap)
Stores a backward reference to the map and key where this cache entry is stored.This is required for the FlexCache.
- Parameters:
theVariationKey
- the variation keytheVariationMap
- the variation map
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
- Returns:
- a basic String representation of this CmsFlexCache entry
- See Also:
Object.toString()
-
-