Class CmsFlexCacheKey

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

public class CmsFlexCacheKey extends 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(String resourcename, String cacheDirectives, boolean online)
    This constructor is used when building a cache key from set of cache directives.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the actual resource path under which this is cached, without online / offline suffix.
    static String
    getKeyName(String resourcename, boolean online)
    Calculates the cache key name that is used as key in the first level of the FlexCache.
    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 String
    Returns the resource.
    static String
    Returns resource name from given key name.
    protected long
    Returns the timeout.
    boolean
    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
    Returns true if 'ignore' directive is set.
    Compares this key to the other key passed as parameter, from comparing the two keys, a variation String is constructed.
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • CmsFlexCacheKey

      public CmsFlexCacheKey(String resourcename, 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 Details

    • getKeyName

      public static String getKeyName(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:
      the FlexCache key name
    • getResourceName

      public static String getResourceName(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

      Returns the actual resource path under which this is cached, without online / offline suffix.

      Returns:
      the actual resource path
    • getPathsForBuckets

      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

      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 String toString()
      Overrides:
      toString in class Object
      Returns:
      a complete String representation for this key
      See Also:
    • getResource

      protected String getResource()
      Returns the resource.

      Returns:
      the resource
    • getTimeout

      protected long getTimeout()
      Returns the timeout.

      Returns:
      the timeout