Class CmsFlexCacheKey
- java.lang.Object
-
- org.opencms.flex.CmsFlexCacheKey
-
public class CmsFlexCacheKey extends java.lang.Object
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
-
-
Constructor Summary
Constructors Constructor Description 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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
getActualResource()
Returns the actual resource path under which this is cached, without online / offline suffix.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.java.util.List<java.lang.String>
getPathsForBuckets(CmsFlexRequestKey key)
Gets the list of root paths for the cache key / request key combination which should be used to determine the set of flex cache buckets for the flex cache entry.protected java.lang.String
getResource()
Returns the resource.static java.lang.String
getResourceName(java.lang.String keyName)
Returns resource name from given key name.protected long
getTimeout()
Returns the timeout.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.boolean
isIgnore()
Returns true if 'ignore' directive is set.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.java.lang.String
toString()
-
-
-
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 rootcacheDirectives
- 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 rootonline
- must be true for an online resource, false for offline resources- Returns:
- the FlexCache key name
-
getResourceName
public static java.lang.String getResourceName(java.lang.String keyName)
Returns resource name from given key name.- Parameters:
keyName
- given name of key.- Returns:
- name of resource if key is valid, otherwise ""
-
getActualResource
public java.lang.String getActualResource()
Returns the actual resource path under which this is cached, without online / offline suffix.- Returns:
- the actual resource path
-
getPathsForBuckets
public java.util.List<java.lang.String> getPathsForBuckets(CmsFlexRequestKey key)
Gets the list of root paths for the cache key / request key combination which should be used to determine the set of flex cache buckets for the flex cache entry.- Parameters:
key
- the flex request key- Returns:
- the list of paths which should be used to determine the flex cache buckets
-
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
-
isIgnore
public boolean isIgnore()
Returns true if 'ignore' directive is set.Mostly the same as 'never', but prevents the 'Cache-Control: public, max-age=0' header from being set
- Returns:
- true if 'ignore' is set
-
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 classjava.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
-
-