PHP Класс Prado\Web\UI\WebControls\TOutputCache

TOutputCache enables caching a portion of a Web page, also known as partial caching. The content being cached can be either static or dynamic. To use TOutputCache, simply enclose the content to be cached within the TOutputCache component tag on a template, e.g., content to be cached where content to be cached can be static text and/or component tags. The validity of the cached content is determined based on two factors: the {@link setDuration Duration} and the cache dependency. The former specifies the number of seconds that the data can remain valid in cache (defaults to 60s), while the latter specifies conditions that the cached data depends on. If a dependency changes, (e.g. relevant data in DB are updated), the cached data will be invalidated. There are two ways to specify cache dependency. One may write event handlers to respond to the {@link onCheckDependency OnCheckDependency} event and set the event parameter's {@link TOutputCacheCheckDependencyEventParameter::getIsValid IsValid} property to indicate whether the cached data remains valid or not. One can also extend TOutputCache and override its {@link getCacheDependency} function. While the former is easier to use, the latter offers more extensibility. The content fetched from cache may be variated with respect to some parameters. It supports variation with respect to request parameters, which is specified by {@link setVaryByParam VaryByParam} property. If a specified request parameter is different, a different version of cached content is used. This is extremely useful if a page's content may be variated according to some GET parameters. The content being cached may also be variated with user sessions if {@link setVaryBySession VaryBySession} is set true. To variate the cached content by other factors, override {@link calculateCacheKey()} method. Output caches can be nested. An outer cache takes precedence over an inner cache. This means, if the content cached by the inner cache expires or is invalidated, while that by the outer cache not, the outer cached content will be used. Note, TOutputCache is effective only for non-postback page requests and when cache module is enabled. Do not attempt to address child controls of TOutputCache when the cached content is to be used. Use {@link getContentCached ContentCached} property to determine whether the content is cached or not.
С версии: 3.1
Автор: Qiang Xue ([email protected])
Наследование: extends Prado\Web\UI\TControl, implements Prado\Web\UI\INamingContainer
Показать файл Открыть проект

Открытые методы

Метод Описание
getAllowChildControls ( ) Returns a value indicating whether body contents are allowed for this control.
getCacheKey ( )
getCacheModuleID ( ) : string
getCacheTime ( ) : integer
getCachingPostBack ( ) : boolean
getContentCached ( ) : boolean
getDuration ( ) : integer
getVaryByParam ( ) : string
getVaryBySession ( ) : boolean
onCalculateKey ( $param ) This event is raised when the output cache is calculating cache key.
onCheckDependency ( $param ) This event is raised when the output cache is checking cache dependency.
registerAction ( $context, $funcName, $funcParams ) Registers an action associated with the content being cached.
render ( $writer ) Renders the output cache control.
setCacheKeyPrefix ( $value ) Sets the prefix of the cache key.
setCacheModuleID ( $value )
setCachingPostBack ( $value ) Sets a value indicating whether cached output will be used on postback requests.
setDuration ( $value )
setVaryByParam ( $value ) : string Sets the names of the request parameters that should be used in calculating the cache key.
setVaryBySession ( $value )

Защищенные методы

Метод Описание
calculateCacheKey ( ) : string Calculates the cache key.
getBaseCacheKey ( ) : string
getCacheDependency ( ) : ICacheDependency Returns the dependency of the data to be cached.
initRecursive ( $namingContainer = null ) Performs the Init step for the control and all its child controls.
loadRecursive ( ) Performs the Load step for the control and all its child controls.
loadStateRecursive ( &$state, $needViewState = true ) Loads state (viewstate and controlstate) into a control and its children.
preRenderRecursive ( ) Performs the PreRender step for the control and all its child controls.
saveStateRecursive ( $needViewState = true ) : array Saves all control state (viewstate and controlstate) as a collection.

Приватные методы

Метод Описание
determineCacheability ( )
performActions ( )

Описание методов

calculateCacheKey() защищенный Метод

The key is calculated based on the unique ID of this control and the request parameters specified via {@link setVaryByParam VaryByParam}. If {@link getVaryBySession VaryBySession} is true, the session ID will also participate in the key calculation. This method may be overriden to support other variations in the calculated cache key.
protected calculateCacheKey ( ) : string
Результат string cache key

getAllowChildControls() публичный Метод

This method overrides the parent implementation by checking if cached content is available or not. If yes, it returns false, otherwise true.

getBaseCacheKey() защищенный Метод

protected getBaseCacheKey ( ) : string
Результат string basic cache key without variations

getCacheDependency() защищенный Метод

The default implementation simply returns null, meaning no specific dependency. This method may be overriden to associate the data to be cached with additional dependencies.
protected getCacheDependency ( ) : ICacheDependency
Результат ICacheDependency

getCacheKey() публичный Метод

public getCacheKey ( )

getCacheModuleID() публичный Метод

public getCacheModuleID ( ) : string
Результат string the ID of the cache module. Defaults to '', meaning the primary cache module is used.

getCacheTime() публичный Метод

С версии: 3.1.1
public getCacheTime ( ) : integer
Результат integer the timestamp of the cached content. This is only valid if the content is being cached.

getCachingPostBack() публичный Метод

public getCachingPostBack ( ) : boolean
Результат boolean whether cached output will be used on postback requests. Defaults to false.

getContentCached() публичный Метод

public getContentCached ( ) : boolean
Результат boolean whether content enclosed is cached or not

getDuration() публичный Метод

public getDuration ( ) : integer
Результат integer number of seconds that the data can remain in cache. Defaults to 60 seconds. Note, if cache dependency changes or cache space is limited, the data may be purged out of cache earlier.

getVaryByParam() публичный Метод

public getVaryByParam ( ) : string
Результат string a semicolon-separated list of strings used to vary the output cache. Defaults to ''.

getVaryBySession() публичный Метод

public getVaryBySession ( ) : boolean
Результат boolean whether the content being cached should be differentiated according to user sessions. Defaults to false.

initRecursive() защищенный Метод

This method overrides the parent implementation by setting up the stack of the output cache in the page. Only framework developers should use this method.
protected initRecursive ( $namingContainer = null )

loadRecursive() защищенный Метод

This method overrides the parent implementation by setting up the stack of the output cache in the page. If the data is restored from cache, it also recovers the actions associated with the cached data. Only framework developers should use this method.
protected loadRecursive ( )

loadStateRecursive() защищенный Метод

This method overrides the parent implementation by loading cached state if available. This method should only be used by framework developers.
protected loadStateRecursive ( &$state, $needViewState = true )

onCalculateKey() публичный Метод

By varying cache keys, one can obtain different versions of cached content. An event handler may be written to add variety of the key calculation. The value set in {@link TOutputCacheCalculateKeyEventParameter::setCacheKey CacheKey} of this event parameter will be appended to the default key calculation scheme.
public onCalculateKey ( $param )

onCheckDependency() публичный Метод

An event handler may be written to check customized dependency conditions. The checking result should be saved by setting {@link TOutputCacheCheckDependencyEventParameter::setIsValid IsValid} property of the event parameter (which defaults to true).
public onCheckDependency ( $param )

preRenderRecursive() защищенный Метод

This method overrides the parent implementation by setting up the stack of the output cache in the page. Only framework developers should use this method.
protected preRenderRecursive ( )

registerAction() публичный Метод

The registered action will be replayed if the content stored in the cache is served to end-users.
public registerAction ( $context, $funcName, $funcParams )

render() публичный Метод

This method overrides the parent implementation by capturing the output from its child controls and saving it into cache, if output cache is needed.
public render ( $writer )

saveStateRecursive() защищенный Метод

This method overrides the parent implementation by saving state into cache if needed. This method should only be used by framework developers.
protected saveStateRecursive ( $needViewState = true ) : array
Результат array the collection of the control state (including its children's state).

setCacheKeyPrefix() публичный Метод

This method is used internally by {@link TTemplate}.
public setCacheKeyPrefix ( $value )

setCacheModuleID() публичный Метод

public setCacheModuleID ( $value )

setCachingPostBack() публичный Метод

By default, this is disabled. Be very cautious when enabling it. If the cached content including interactive user controls such as TTextBox, TDropDownList, your page may fail to render on postbacks.
public setCachingPostBack ( $value )

setDuration() публичный Метод

public setDuration ( $value )

setVaryByParam() публичный Метод

The names should be concatenated by semicolons. By setting this value, the output cache will use different cached data for each different set of request parameter values.
public setVaryByParam ( $value ) : string
Результат string a semicolon-separated list of strings used to vary the output cache.

setVaryBySession() публичный Метод

public setVaryBySession ( $value )