Package org.ametys.web.cache.pageelement
Class PageElementCache
- java.lang.Object
-
- org.ametys.runtime.plugin.component.AbstractLogEnabled
-
- org.ametys.web.cache.pageelement.PageElementCache
-
- All Implemented Interfaces:
LogEnabled
,PluginAware
,Disposable
,Initializable
,Component
,Configurable
,Contextualizable
,Serviceable
public class PageElementCache extends AbstractLogEnabled implements Component, Contextualizable, Disposable, Serviceable, Initializable, PluginAware, Configurable
Cache the page elements renderings.
This class handles several caches, one per site and per JCR workspace.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
PageElementCache.PageElementKey
-
Field Summary
Fields Modifier and Type Field Description private AbstractCacheManager
_cacheManager
private Context
_context
private I18nizableText
_description
private Map<String,Map<String,Map<String,String>>>
_elementCache
private String
_id
private I18nizableText
_label
private String
_pluginName
static String
DISABLE_PE_CACHE_ATTRIBUTE
"Disable page element cache" request attribute.static String
ROLE
Avalon role.
-
Constructor Summary
Constructors Constructor Description PageElementCache()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private Cache<PageElementCache.PageElementKey,SaxBuffer>
_getCache()
void
clear()
Removes all stored data.void
clear(String workspace, String site)
Removes all data associated with a JCR workspace and a site.void
clear(String workspace, String site, String pageElementType)
Removes all data associated with a JCR workspace, a site and a given element type.void
configure(Configuration configuration)
void
contextualize(Context context)
void
dispose()
Collection<String>
getElementCache(String workspace, String site, String pageElementType)
Returns all cached data for a given InputData, or null if none.SaxBuffer
getPageElement(String workspace, String site, String pageElementType, String elementId, String subElementId, RenderingContext renderingContext)
Returns the data in the cache, or null if none.SaxBuffer
getPageElement(String workspace, String site, String pageElementType, String elementId, RenderingContext renderingContext)
Returns the data in the cache, or null if none.Set<String>
getPageElementTypes(String workspace, String site)
Returns all stored element types, or null if none.void
initialize()
protected boolean
isEnabled()
Test if the cache is enabled.void
removeItem(String workspace, String site, String pageElementType, String elementId)
Removes a single item from the cache.void
service(ServiceManager manager)
void
setPluginInfo(String pluginName, String featureName, String id)
Sets the plugin info relative to the current component.
Note : The feature name may be null if the targeted component in declared at plugin level.void
storePageElement(String workspace, String site, String pageElementType, String elementId, String subElementId, RenderingContext renderingContext, SaxBuffer content)
Add a content in the cache.void
storePageElement(String workspace, String site, String pageElementType, String elementId, RenderingContext renderingContext, SaxBuffer content)
Add a content in the cache.-
Methods inherited from class org.ametys.runtime.plugin.component.AbstractLogEnabled
getLogger, setLogger
-
-
-
-
Field Detail
-
DISABLE_PE_CACHE_ATTRIBUTE
public static final String DISABLE_PE_CACHE_ATTRIBUTE
"Disable page element cache" request attribute.- See Also:
- Constant Field Values
-
_cacheManager
private AbstractCacheManager _cacheManager
-
_pluginName
private String _pluginName
-
_label
private I18nizableText _label
-
_description
private I18nizableText _description
-
-
Constructor Detail
-
PageElementCache
public PageElementCache()
-
-
Method Detail
-
service
public void service(ServiceManager manager) throws ServiceException
- Specified by:
service
in interfaceServiceable
- Throws:
ServiceException
-
configure
public void configure(Configuration configuration) throws ConfigurationException
- Specified by:
configure
in interfaceConfigurable
- Throws:
ConfigurationException
-
contextualize
public void contextualize(Context context) throws ContextException
- Specified by:
contextualize
in interfaceContextualizable
- Throws:
ContextException
-
setPluginInfo
public void setPluginInfo(String pluginName, String featureName, String id)
Description copied from interface:PluginAware
Sets the plugin info relative to the current component.
Note : The feature name may be null if the targeted component in declared at plugin level.- Specified by:
setPluginInfo
in interfacePluginAware
- Parameters:
pluginName
- Unique identifier for the plugin hosting the extensionfeatureName
- Unique feature identifier (unique for a given pluginName)id
- Unique identifier of this component
-
initialize
public void initialize() throws Exception
- Specified by:
initialize
in interfaceInitializable
- Throws:
Exception
-
storePageElement
public void storePageElement(String workspace, String site, String pageElementType, String elementId, RenderingContext renderingContext, SaxBuffer content)
Add a content in the cache.- Parameters:
workspace
- the current JCR workspace.site
- the current site.pageElementType
- the page element type.elementId
- the element id (page id or zoneItem id).renderingContext
- the current rendering context.content
- the actual content.
-
storePageElement
public void storePageElement(String workspace, String site, String pageElementType, String elementId, String subElementId, RenderingContext renderingContext, SaxBuffer content)
Add a content in the cache.- Parameters:
workspace
- the current JCR workspace.site
- the current site.pageElementType
- the page element type.elementId
- the element id (page id or zoneItem id).subElementId
- the sub-element id (page id, in case the element id is a zoneItem id).renderingContext
- the current rendering context.content
- the actual content.
-
getPageElement
public SaxBuffer getPageElement(String workspace, String site, String pageElementType, String elementId, RenderingContext renderingContext)
Returns the data in the cache, or null if none.- Parameters:
workspace
- the current JCR workspace.site
- the current site.pageElementType
- the element type.elementId
- the element id (page id or zoneItem id).renderingContext
- the current rendering context.- Returns:
- the stored content.
-
getPageElement
public SaxBuffer getPageElement(String workspace, String site, String pageElementType, String elementId, String subElementId, RenderingContext renderingContext)
Returns the data in the cache, or null if none.- Parameters:
workspace
- the current JCR workspace.site
- the current site.pageElementType
- the element type.elementId
- the element id (page id or zoneItem id).subElementId
- the sub-element id (page id, in case the element id is a zoneItem id).renderingContext
- the current rendering context.- Returns:
- the stored content.
-
getPageElementTypes
public Set<String> getPageElementTypes(String workspace, String site)
Returns all stored element types, or null if none.- Parameters:
workspace
- the current JCR workspace.site
- the current site.- Returns:
- all stored element types.
-
getElementCache
public Collection<String> getElementCache(String workspace, String site, String pageElementType)
Returns all cached data for a given InputData, or null if none.- Parameters:
workspace
- the current JCR workspace.site
- the current site.pageElementType
- the element type.- Returns:
- the stored content.
-
removeItem
public void removeItem(String workspace, String site, String pageElementType, String elementId)
Removes a single item from the cache.- Parameters:
workspace
- the target JCR workspace or null to remove from all workspaces.site
- the target site.pageElementType
- the element type.elementId
- the element id.
-
clear
public void clear()
Removes all stored data.
-
clear
public void clear(String workspace, String site)
Removes all data associated with a JCR workspace and a site.- Parameters:
workspace
- the current JCR workspace. If null, means all workspaces.site
- the current site.
-
clear
public void clear(String workspace, String site, String pageElementType)
Removes all data associated with a JCR workspace, a site and a given element type.- Parameters:
workspace
- the current JCR workspace.site
- the current site.pageElementType
- the element type.
-
dispose
public void dispose()
- Specified by:
dispose
in interfaceDisposable
-
isEnabled
protected boolean isEnabled()
Test if the cache is enabled.- Returns:
- true if the cache is enabled, false otherwise.
-
_getCache
private Cache<PageElementCache.PageElementKey,SaxBuffer> _getCache()
-
-