public class Cache extends OutputFamily
The <o:cache>
component allows to cache a fragment of rendered markup. The first
request for a page that has this component on it will cause this markup to be put into the cache. Then
for subsequent requests the cached content is used directly and none of the components, backing beans
and services that were used to generate this content in the first place will be consulted.
Caching can take place in application scope, or in session scope. For individual fragments a time can be specified for which the cached content is valid. After this time is elapsed, the very first request to the page containing the cache component in question will cause new content to be rendered and put into the cache. A default time can be set per scope in web.xml.
For each scope a maximum capacity can be set. If the capacity for that scope is exceeded, an element will be removed following a least recently used policy (LRU).
Via a cache provider mechanism an alternative cache implementation can be configured in web.xml. The default cache is based on https://github.com/ben-manes/concurrentlinkedhashmap.
A custom caching provider can be set by using the org.omnifaces.CACHE_PROVIDER
context
parameter in web.xml to point to an implementation of org.omnifaces.component.output.cache.CacheProvider
.
For example:
<context-param> <param-name>org.omnifaces.CACHE_PROVIDER</param-name> <param-value>com.example.MyProvider</param-value> </context-param>
The default provider, org.omnifaces.component.output.cache.DefaultCacheProvider
can be used as an
example.
For the default provider, the maximum capacity and the default time to live can be specified for the
supported scopes "session" and "application". If the maximum capacity is reached, an entry will be
evicted following a least recently used policy. The default time to live specifies for how long
entries are considered to be valid. A value for the time
attribute on this component
will override this global default time to live. The following context parameters can be used in web.xml:
org.omnifaces.CACHE_SETTING_APPLICATION_MAX_CAPACITY
| Sets the maximum number of elements that will be stored per web module (application scope). Default: no limit |
org.omnifaces.CACHE_SETTING_SESSION_MAX_CAPACITY
| Sets the maximum number of elements that will be stored per session. Default: no limit. |
org.omnifaces.CACHE_SETTING_APPLICATION_TTL
| Sets the maximum amount of time in seconds that cached content is valid for the application scope. Can be overriden by individal cache components. Default: no limit. |
org.omnifaces.CACHE_SETTING_SESSION_TTL
| Sets the maximum amount of time in seconds that cached content is valid for the session scope. Can be overriden by individal cache components. Default: no limit. |
org.omnifaces.CACHE_INSTALL_BUFFER_FILTER
|
Boolean that when true installs a Servlet Filter (Servlet 3.0+ only) that works in conjunction with the
useBuffer attribute of the Cache component to enable an alternative way to grab the content that needs
to be cached. This is a convenience setting that is a short-cut for installing the
org.omnifaces.servlet.BufferedHttpServletResponse filter manually. If more finegrained control is needed
regarding which place in the filter chain the filter appears and which resources it exactly filters, this setting
should not be used and the mentioned filter should be manually configured.
Default: false .
|
Cache
,
CacheEntry
,
CacheFactory
,
CacheInitializer
,
CacheInstancePerScopeProvider
,
CacheProvider
,
DefaultCache
,
DefaultCacheProvider
,
TimeToLiveCache
,
CacheValue
,
CachingValueExpression
,
OnDemandResponseBufferFilter
,
BufferedHttpServletResponse
,
HttpServletResponseOutputWrapper
,
ResettableBuffer
,
ResettableBufferedOutputStream
,
ResettableBufferedWriter
,
OutputFamily
Modifier and Type | Field and Description |
---|---|
static String |
COMPONENT_TYPE |
static String |
DEFAULT_SCOPE |
static String |
END_CONTENT_MARKER |
static String |
START_CONTENT_MARKER |
static String |
VALUE_SET |
COMPONENT_FAMILY
ATTRS_WITH_DECLARED_DEFAULT_VALUES, BEANINFO_KEY, bindings, COMPOSITE_COMPONENT_TYPE_KEY, COMPOSITE_FACET_NAME, CURRENT_COMPONENT, CURRENT_COMPOSITE_COMPONENT, FACETS_KEY, HONOR_CURRENT_COMPONENT_ATTRIBUTES_PARAM_NAME, VIEW_LOCATION_KEY
Constructor and Description |
---|
Cache() |
Modifier and Type | Method and Description |
---|---|
void |
encodeChildren(FacesContext context) |
Object |
getCacheAttribute(FacesContext context,
String name)
Gets a named attribute associated with the main cache entry this component is using to store
the rendering of its child components.
|
String |
getKey() |
String |
getScope() |
Integer |
getTime() |
boolean |
isDisabled()
Returns whether this cache is disabled.
|
boolean |
isReset() |
boolean |
isUseBuffer() |
protected boolean |
isVisitable(VisitContext visitContext) |
void |
setCacheAttribute(FacesContext context,
String name,
Object value)
Sets a named attribute associated with the main cache entry this component is using to store
the rendering of its child components.
|
void |
setDisabled(boolean disabledValue)
Sets whether this cache is disabled.
|
void |
setKey(String keyValue) |
void |
setReset(boolean resetValue) |
void |
setScope(String scopeValue) |
void |
setTime(Integer timeValue) |
void |
setUseBuffer(boolean useBufferValue) |
getFamily, getRendersChildren
addClientBehavior, addFacesListener, broadcast, clearInitialState, decode, encodeBegin, encodeEnd, findComponent, getAttributes, getChildCount, getChildren, getClientBehaviors, getClientId, getDefaultEventName, getEventNames, getFacesContext, getFacesListeners, getFacet, getFacetCount, getFacets, getFacetsAndChildren, getId, getListenersForEventClass, getParent, getPassThroughAttributes, getRenderer, getRendererType, getValueBinding, invokeOnComponent, isRendered, isTransient, markInitialState, processDecodes, processRestoreState, processSaveState, processUpdates, processValidators, queueEvent, removeFacesListener, restoreAttachedState, restoreState, saveAttachedState, saveState, setId, setParent, setRendered, setRendererType, setTransient, setValueBinding, subscribeToEvent, unsubscribeFromEvent
encodeAll, getClientId, getCompositeComponentParent, getContainerClientId, getCurrentComponent, getCurrentCompositeComponent, getNamingContainer, getPassThroughAttributes, getResourceBundleMap, getStateHelper, getStateHelper, getTransientStateHelper, getTransientStateHelper, getValueExpression, initialStateMarked, isCompositeComponent, isInView, popComponentFromEL, processEvent, pushComponentToEL, restoreTransientState, saveTransientState, setInView, setValueExpression, visitTree
public static final String COMPONENT_TYPE
public static final String VALUE_SET
public static final String DEFAULT_SCOPE
public static final String START_CONTENT_MARKER
public static final String END_CONTENT_MARKER
public void encodeChildren(FacesContext context) throws IOException
encodeChildren
in class UIComponentBase
IOException
public Object getCacheAttribute(FacesContext context, String name)
context
- the current FacesContextname
- name of the attribute to retrieve a value forpublic void setCacheAttribute(FacesContext context, String name, Object value)
context
- the current FacesContextname
- name of the attribute under which the value is storedvalue
- the value that is to be storedprotected boolean isVisitable(VisitContext visitContext)
isVisitable
in class UIComponent
public String getKey()
public void setKey(String keyValue)
public String getScope()
public void setScope(String scopeValue)
public Integer getTime()
public void setTime(Integer timeValue)
public boolean isUseBuffer()
public void setUseBuffer(boolean useBufferValue)
public boolean isReset()
public void setReset(boolean resetValue)
public boolean isDisabled()
public void setDisabled(boolean disabledValue)
disabledValue
- Whether this cache is disabled.Copyright © 2012–2018 OmniFaces. All rights reserved.