org.opencms.flex
Class CmsFlexCacheKey

java.lang.Object
  extended by org.opencms.flex.CmsFlexCacheKey

public class CmsFlexCacheKey
extends java.lang.Object

Implements the CmsFlexCacheKey, which is a key used to describe the caching behaviour of a specific resource.

It has a lot of variables that are directly accessed (which isn't good style, I know) to avoid method calling overhead (a cache is about speed, isn't it :).

Since:
6.0.0
Version:
$Revision: 1.35 $
Author:
Alexander Kandzior

Constructor Summary
CmsFlexCacheKey(java.lang.String resourcename, java.lang.String cacheDirectives, boolean online)
          This constructor is used when building a cache key from set of cache directives.
 
Method Summary
static java.lang.String getKeyName(java.lang.String resourcename, boolean online)
          Calculates the cache key name that is used as key in the first level of the FlexCache.
protected  java.lang.String getResource()
          Returns the resource.
protected  long getTimeout()
          Returns the timeout.
protected  java.lang.String getVariation()
          Returns the variation.
 boolean hadParseError()
          This flag is used to indicate that a parse error had occurred, which can happen if the cache directives String passed to the constructor using the response is not build according to the Flex cache language syntax.
 java.lang.String matchRequestKey(CmsFlexRequestKey key)
          Compares this key to the other key passed as parameter, from comparing the two keys, a variation String is constructed.
protected  void setVariation(java.lang.String variation)
          Sets the variation.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CmsFlexCacheKey

public CmsFlexCacheKey(java.lang.String resourcename,
                       java.lang.String cacheDirectives,
                       boolean online)
This constructor is used when building a cache key from set of cache directives.

These directives are attached to the properties of the requested resource on a property called "cache". The value of this poperty that is passed in this constructor as "cacheDirectives" is parsed to build the keys data structure.

In case a parsing error occures, the value of this key is set to "cache=never", and the hadParseError() flag is set to true. This is done to ensure that a valid key is always constructed with the constructor.

Parameters:
resourcename - the full name of the resource including site root
cacheDirectives - the cache directives of the resource (value of the property "cache")
online - must be true for an online resource, false for offline resources
Method Detail

getKeyName

public static java.lang.String getKeyName(java.lang.String resourcename,
                                          boolean online)
Calculates the cache key name that is used as key in the first level of the FlexCache.

Parameters:
resourcename - the full name of the resource including site root
online - must be true for an online resource, false for offline resources
Returns:
fhe FlexCache key name

hadParseError

public boolean hadParseError()
This flag is used to indicate that a parse error had occurred, which can happen if the cache directives String passed to the constructor using the response is not build according to the Flex cache language syntax.

Returns:
true if a parse error did occur, false otherwise

matchRequestKey

public java.lang.String matchRequestKey(CmsFlexRequestKey key)
Compares this key to the other key passed as parameter, from comparing the two keys, a variation String is constructed.

This method is the "heart" of the key matching process.

The assumtion is that this key should be the one constructed for the response, while the parameter key should have been constructed from the request.

A short example how this works: If the cache key is "cache=user" and the request is done from a guest user the constructed variation will be "user=(guest)".

Parameters:
key - the key to match this key with
Returns:
null if not cachable, or the Variation String if cachable

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
Returns:
a complete String representation for this key
See Also:
Object.toString()

getResource

protected java.lang.String getResource()
Returns the resource.

Returns:
the resource

getTimeout

protected long getTimeout()
Returns the timeout.

Returns:
the timeout

getVariation

protected java.lang.String getVariation()
Returns the variation.

Returns:
the variation

setVariation

protected void setVariation(java.lang.String variation)
Sets the variation.

Parameters:
variation - the variation to set