com.opencms.flex.cache
Class CmsFlexCacheKey

java.lang.Object
  |
  +--com.opencms.flex.cache.CmsFlexCacheKey

public class CmsFlexCacheKey
extends Object

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

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

Version:
$Revision: 1.7 $
Author:
Alexander Kandzior (a.kandzior@alkacon.com)

Field Summary
 int m_always
          Cache key variable: Determines if this resource can be cached alwys, never or under certain conditions. -1 = never, 0=check, 1=always
 Set m_groups
          Cache key variable: List of groups
 Set m_noparams
          Cache key variable: List of "blocking" parameters
 Map m_params
          Cache key variable: List of parameters
 Set m_ports
          Cache key variable: The request TCP/IP port
 boolean m_publish
          Cache key variable: Determines if the resource sould be always cleared at publish time
 Set m_schemes
          Cache key variable: Distinguishes request schemes (http, https etc.)
 long m_timeout
          Cache key variable: Timeout of the resource
 String m_uri
          Cache key variable: The uri of the original request
 int m_user
          Cache key variable: The user id
 String Resource
          The OpenCms resource that this key is used for.
 String Variation
          The cache behaviour description for the resource.
 
Constructor Summary
CmsFlexCacheKey(CmsFlexRequest request, String target, boolean online)
          This constructor is used when building a cache key from a request.
CmsFlexCacheKey(String target, String cacheDirectives, boolean online)
          This constructor is used when building a cache key from set of cache directives.
 
Method Summary
static String getKeyName(String name, boolean online)
          Calculates the cache key name that is used as key in the first level of the FlexCache.
 boolean hadParseError()
          This flag is used to indicate that a parse error had occured, 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.
 String matchRequestKey(CmsFlexCacheKey key)
          Compares this key to the other key passed as parameter, from comparing the two keys, a variation String is constructed.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

Resource

public String Resource
The OpenCms resource that this key is used for.


Variation

public String Variation
The cache behaviour description for the resource.


m_always

public int m_always
Cache key variable: Determines if this resource can be cached alwys, never or under certain conditions. -1 = never, 0=check, 1=always


m_uri

public String m_uri
Cache key variable: The uri of the original request


m_user

public int m_user
Cache key variable: The user id


m_groups

public Set m_groups
Cache key variable: List of groups


m_params

public Map m_params
Cache key variable: List of parameters


m_noparams

public Set m_noparams
Cache key variable: List of "blocking" parameters


m_timeout

public long m_timeout
Cache key variable: Timeout of the resource


m_publish

public boolean m_publish
Cache key variable: Determines if the resource sould be always cleared at publish time


m_schemes

public Set m_schemes
Cache key variable: Distinguishes request schemes (http, https etc.)


m_ports

public Set m_ports
Cache key variable: The request TCP/IP port

Constructor Detail

CmsFlexCacheKey

public CmsFlexCacheKey(CmsFlexRequest request,
                       String target,
                       boolean online)
This constructor is used when building a cache key from a request.

The request contains several data items that are neccessary to construct the output. These items are e.g. the Query-String, the requested resource, the current time etc. etc. All required items are saved in the constructed cache - key.

Parameters:
target - the requested resource in the OpenCms VFS
online - must be true for an online resource, false for offline resources
request - the request to construct the key for

CmsFlexCacheKey

public CmsFlexCacheKey(String target,
                       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:
target - the requested resource
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 String getKeyName(String name,
                                boolean online)
Calculates the cache key name that is used as key in the first level of the FlexCache.

Parameters:
name - the name of the resource
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 occured, 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 String matchRequestKey(CmsFlexCacheKey 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 resource key is "cache=groups" and the request is done from a guest user (which always belongs to the default group "guests"), the constructed variation will be "groups=(guests)".

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

toString

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