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 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 String UUID_KEY_MAP_KEY
           
 
Constructor Summary
Default()
           
 
Method Summary
 info.magnolia.voting.voters.VoterSet getVoters()
           
 boolean isRefreshOnNoCacheRequests()
           
 void persistCacheKey(String repo, String uuid, Object key)
          Presists mapping between uuid and cache key in case the given cache policy implementation cares about such details.
 Object[] removeCacheKeys(String uuid, 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.
 Object retrieveCacheKey(info.magnolia.cms.core.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.
 Object[] retrieveCacheKeys(String uuid, 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(info.magnolia.voting.voters.VoterSet voters)
           
protected  boolean shouldBypass(info.magnolia.cms.core.AggregationState aggregationState, Object key)
           
 CachePolicyResult shouldCache(Cache cache, info.magnolia.cms.core.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(info.magnolia.cms.core.AggregationState aggregationState, 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 String UUID_KEY_MAP_KEY
See Also:
Constant Field Values
Constructor Detail

Default

public Default()
Method Detail

shouldCache

public CachePolicyResult shouldCache(Cache cache,
                                     info.magnolia.cms.core.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(info.magnolia.cms.core.AggregationState aggregationState,
                                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(info.magnolia.cms.core.AggregationState aggregationState,
                               Object key)

retrieveCacheKey

public Object retrieveCacheKey(info.magnolia.cms.core.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 Object[] retrieveCacheKeys(String uuid,
                                  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(String repo,
                            String uuid,
                            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 info.magnolia.voting.voters.VoterSet getVoters()

setVoters

public void setVoters(info.magnolia.voting.voters.VoterSet voters)

removeCacheKeys

public Object[] removeCacheKeys(String uuid,
                                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.