public abstract class AbstractCacheKeyGenerator extends Object implements ICacheKeyGenerator
ICacheKeyGenerator
.
Implements default cache key generator behavior for module builders that d don't need provisional cache key generators and don't need combine logic.
Constructor and Description |
---|
AbstractCacheKeyGenerator() |
Modifier and Type | Method and Description |
---|---|
ICacheKeyGenerator |
combine(ICacheKeyGenerator other)
Combines this cache key generator with the specified cache key generator
so that the cache key returned by the resulting generator can be used to
identify a layer build containing the module(s) represented by this cache
key generator as well as the module(s) represented by the specified cache
key generator.
|
abstract String |
generateKey(javax.servlet.http.HttpServletRequest request)
Returns a string that will be used to identify cached responses for the
specified request.
|
List<ICacheKeyGenerator> |
getCacheKeyGenerators(javax.servlet.http.HttpServletRequest request)
This method returns the (possibly empty) list of constituent cache key
generators belonging to a composite cache key generator.
|
boolean |
isProvisional()
Instances of this object can be provisional.
|
abstract String |
toString()
Cache key generators should implement this function to return a short
keyword identifier for the generator (typically the same keyword used
in generated keys) plus a string representation of the instance data
that is used in constructing the keys (if any).
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
equals
public abstract String generateKey(javax.servlet.http.HttpServletRequest request)
ICacheKeyGenerator
For clarity's sake, keys should avoid using semi-colons since these are used as a separator when aggregating the keys from multiple cache key generators.
Note that IOptions
properties do not need to be factored into the
returned key since any changes in these properties invalidates cached
responses and clears the module and layer caches.
generateKey
in interface ICacheKeyGenerator
request
- The request objectpublic ICacheKeyGenerator combine(ICacheKeyGenerator other)
ICacheKeyGenerator
For most implementations, these two generators will be identical and a reference to the current object should be returned. Only implementations who's cache keys are dependent on module content or other factors external to the request object need to provide a non-trivial implementation for this method. An example would be a javascript minifier which performs has.js feature trimming of code based on the list of feature names provided in the request. Cache keys for this module might identify the feature conditionals that the module actually contains, allowing cached module builds to be reused for requests that specify the same values for the set of features that are of concern to the module while ignoring those that are not relevant. In this example, the combine method would create a new CacheKeyGenerator from the union of the feature name sets from this generator and the specified generator.
If either this cache key generator or the specified cached key generator is a provisional cache key generator and the other is not, the returned object must be a non-provisional cache key generator.
If combining this cache key generator with the specified cache key generator yields a cache key generator that produces identical cache keys as this cache key generator, then this cache key generator should be returned.
combine
in interface ICacheKeyGenerator
other
- A reference to the CacheKeyGenerator object that is to be
combined with this object. The Aggregator guarantees that
other
will be of the same type as the current object,
so it is always safe to cast other
to an instance of
the current object.other
will produce a cache key
generator that generates the same keys as this object.public List<ICacheKeyGenerator> getCacheKeyGenerators(javax.servlet.http.HttpServletRequest request)
ICacheKeyGenerator
Composite cache key generators are useful for controlling the output of other cache key generators in ways that depend on aspects of the current request that are outside the scope of the key generator being controlled. Composite cache key generators must adhere to the following restrictions:
ICacheKeyGenerator.generateKey(HttpServletRequest)
method for
this cache key generator should be the same as the combined (semi-colon
delimited) output of the generateKey
methods for the cache key
generators returned by this method.getCacheKeyGenerators
in interface ICacheKeyGenerator
request
- The request objectpublic boolean isProvisional()
ICacheKeyGenerator
IModuleBuilder.getCacheKeyGenerators(IAggregator)
should return a
provisional cache key generator, which generates keys based on
information available in the request only. The builder should then
provide a non-provisional cache key generator in the ModuleBuild
object returned from
IModuleBuilder.build(String, IResource, HttpServletRequest, List)
when it is subsequently called by a separate worker thread for the same
request.
The cache key returned by a provisional cache key generator must be either more specific than, or as specific as, the cache key returned by a non-provisional cache key generator for the same module with the same request parameters. The requirement is that if a provisional cache key generator returns identical keys for two different requests, then the non-provisional cache key generator must also return identical keys for the same two requests. The converse is not a requirement.
Provisional cache key generators are used to allow the module cache manager to cache module builds while they are still pending, potentially allowing an in-progress build to satisfy other outstanding requests. This need arises when information about the contents of the module, which is gained in the process of building it, can be used to broaden the scope of the key by ignoring request parameters or features that are not applicable to the module as determined by its content.
isProvisional
in interface ICacheKeyGenerator
public abstract String toString()
ICacheKeyGenerator
toString
in interface ICacheKeyGenerator
toString
in class Object
Copyright © 2011-2015 IBM. All Rights Reserved.