info.magnolia.module.cache.cachepolicy
Class Default

java.lang.Object
  extended by info.magnolia.module.cache.cachepolicy.Default
All Implemented Interfaces:
CachePolicy

public class Default
extends java.lang.Object
implements CachePolicy

A basic CachePolicy driven by voters. This policy implementation uses DefaultCacheKey to identify each cache entry.

Version:
$Revision: 1821 $ ($Author: fgiust $)
Author:
gjoseph

Field Summary
static java.lang.String UUID_KEY_MAP_KEY
           
 
Constructor Summary
Default()
           
 
Method Summary
 VoterSet getVoters()
           
 boolean isRefreshOnNoCacheRequests()
           
 void persistCacheKey(java.lang.String repo, java.lang.String uuid, java.lang.Object key)
          Presists mapping between uuid and cache key in case the given cache policy implementation cares about such details.
 java.lang.Object[] removeCacheKeys(java.lang.String uuid, java.lang.String repository)
          Returns cache keys for the given item or null if such keys can't be obtained or policy doesn't want to share it.
 java.lang.Object retrieveCacheKey(AggregationState aggregationState)
          Returns cache key for the given item or null if such key can't be obtained or policy doesn't want to share it.
 java.lang.Object[] retrieveCacheKeys(java.lang.String uuid, java.lang.String repository)
          Returns cache keys for the given item or null if such keys can't be obtained or policy doesn't want to share it.
 void setRefreshOnNoCacheRequests(boolean allowNoCacheHeader)
           
 void setVoters(VoterSet voters)
           
protected  boolean shouldBypass(AggregationState aggregationState, java.lang.Object key)
           
 CachePolicyResult shouldCache(Cache cache, AggregationState aggregationState, FlushPolicy flushPolicy)
          Implementations can chose whether to cache or not - but note that the aggregationState might not be completely populated.
protected  boolean shouldRefresh(AggregationState aggregationState, java.lang.Object key)
          Checks whether requested content should be served from cache or refreshed instead.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UUID_KEY_MAP_KEY

public static final java.lang.String UUID_KEY_MAP_KEY
See Also:
Constant Field Values
Constructor Detail

Default

public Default()
Method Detail

shouldCache

public CachePolicyResult shouldCache(Cache cache,
                                     AggregationState aggregationState,
                                     FlushPolicy flushPolicy)
Description copied from interface: CachePolicy
Implementations can chose whether to cache or not - but note that the aggregationState might not be completely populated. Every request should be cacheable, not only those processed through Magnolia's RenderingFilter.

Specified by:
shouldCache in interface CachePolicy

shouldRefresh

protected boolean shouldRefresh(AggregationState aggregationState,
                                java.lang.Object key)
Checks whether requested content should be served from cache or refreshed instead.

Returns:
True if cache entry for the key should be recreated, false otherwise.

shouldBypass

protected boolean shouldBypass(AggregationState aggregationState,
                               java.lang.Object key)

retrieveCacheKey

public java.lang.Object retrieveCacheKey(AggregationState aggregationState)
Description copied from interface: CachePolicy
Returns cache key for the given item or null if such key can't be obtained or policy doesn't want to share it. When using aggregationState, key is expected to be composed with aggregated request in mind and policy has to choose only one such key denoting item to return to the client, if such an item indeed exists and can be served. When not existing key might be used to store the cache entry. Since only one version of the content can be streamed back to the client, it makes sense to create only one cache entry for the such a key as well.

Specified by:
retrieveCacheKey in interface CachePolicy

retrieveCacheKeys

public java.lang.Object[] retrieveCacheKeys(java.lang.String uuid,
                                            java.lang.String repository)
Description copied from interface: CachePolicy
Returns cache keys for the given item or null if such keys can't be obtained or policy doesn't want to share it. Since in this case uuid is used to retrieve the cache key, it is quite possible that multiple different representations of the content denoted by uuid exist and all such keys should be returned leaving it up to requesting object to deal with such a multiplicity. Please note that returned keys might not be necessary multiple representations of the content denoted by provided uuid, but also quite possibly all the content deemed related or partially used to construct any of the returned cache keys.

Specified by:
retrieveCacheKeys in interface CachePolicy

persistCacheKey

public void persistCacheKey(java.lang.String repo,
                            java.lang.String uuid,
                            java.lang.Object key)
Description copied from interface: CachePolicy
Presists mapping between uuid and cache key in case the given cache policy implementation cares about such details.

Specified by:
persistCacheKey in interface CachePolicy

getVoters

public VoterSet getVoters()

setVoters

public void setVoters(VoterSet voters)

removeCacheKeys

public java.lang.Object[] removeCacheKeys(java.lang.String uuid,
                                          java.lang.String repository)
Description copied from interface: CachePolicy
Returns cache keys for the given item or null if such keys can't be obtained or policy doesn't want to share it. Since in this case uuid is used to retrieve the cache key, it is quite possible that multiple different representations of the content denoted by uuid exist and all such keys should be returned leaving it up to requesting object to deal with such a multiplicity. Please note that returned keys might not be necessary multiple representations of the content denoted by provided uuid, but also quite possibly all the content deemed related or partially used to construct any of the returned cache keys. At the call to this method, cache policy should not only return the keys associated with the uuid, but also remove all returned uuid-cahce key mappings.

Specified by:
removeCacheKeys in interface CachePolicy

isRefreshOnNoCacheRequests

public boolean isRefreshOnNoCacheRequests()

setRefreshOnNoCacheRequests

public void setRefreshOnNoCacheRequests(boolean allowNoCacheHeader)


Copyright © 2003-2011 Magnolia International Ltd.. All Rights Reserved.