Overview

Packages

  • application
    • commands
    • components
      • actions
      • filters
      • leftWidget
      • permissions
      • sortableWidget
      • util
      • webupdater
      • x2flow
        • actions
        • triggers
      • X2GridView
      • X2Settings
    • controllers
    • models
      • embedded
    • modules
      • accounts
        • controllers
        • models
      • actions
        • controllers
        • models
      • calendar
        • controllers
        • models
      • charts
        • models
      • contacts
        • controllers
        • models
      • docs
        • components
        • controllers
        • models
      • groups
        • controllers
        • models
      • marketing
        • components
        • controllers
        • models
      • media
        • controllers
        • models
      • mobile
        • components
      • opportunities
        • controllers
        • models
      • products
        • controllers
        • models
      • quotes
        • controllers
        • models
      • services
        • controllers
        • models
      • template
        • models
      • users
        • controllers
        • models
      • workflow
        • controllers
        • models
      • x2Leads
        • controllers
        • models
  • Net
  • None
  • PHP
  • system
    • base
    • caching
      • dependencies
    • collections
    • console
    • db
      • ar
      • schema
        • cubrid
        • mssql
        • mysql
        • oci
        • pgsql
        • sqlite
    • i18n
      • gettext
    • logging
    • test
    • utils
    • validators
    • web
      • actions
      • auth
      • filters
      • form
      • helpers
      • renderers
      • services
      • widgets
        • captcha
        • pagers
  • Text
    • Highlighter
  • zii
    • behaviors
    • widgets
      • grid
      • jui

Classes

  • ActionActiveForm
  • ActionActiveFormBase
  • CActiveForm
  • CalendarEventActiveForm
  • CallActiveForm
  • CClipWidget
  • CContentDecorator
  • CFilterWidget
  • CFlexWidget
  • CHtmlPurifier
  • CInputWidget
  • CMarkdown
  • CMaskedTextField
  • CMultiFileUpload
  • COutputCache
  • COutputProcessor
  • CStarRating
  • CTabView
  • CTextHighlighter
  • CTreeView
  • CWidget
  • EventActiveForm
  • MobileActiveForm
  • NoteActiveForm
  • TimeActiveForm
  • X2ActiveForm
  • X2StarRating
  • Overview
  • Package
  • Class
  • Tree

Class COutputCache

COutputCache enables caching the output generated by an action or a view fragment.

If the output to be displayed is found valid in cache, the cached version will be displayed instead, which saves the time for generating the original output.

Since COutputCache extends from CFilterWidget, it can be used as either a filter (for action caching) or a widget (for fragment caching). For the latter, the shortcuts CBaseController::beginCache() and CBaseController::endCache() are often used instead, like the following in a view file:

if($this->beginCache('cacheName',array('property1'=>'value1',...))
{
    // ... display the content to be cached here
   $this->endCache();
}

COutputCache must work with a cache application component specified via COutputCache::$cacheID. If the cache application component is not available, COutputCache will be disabled.

The validity of the cached content is determined based on two factors: the COutputCache::$duration and the cache COutputCache::$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. For more details about cache dependency, see CCacheDependency.

Sometimes, it is necessary to turn off output caching only for certain request types. For example, we only want to cache a form when it is initially requested; any subsequent display of the form should not be cached because it contains user input. We can set COutputCache::$requestTypes to be <span class="php-keyword1">array</span>(<span class="php-quote">'GET'</span>) to accomplish this task.

The content fetched from cache may be variated with respect to some parameters. COutputCache supports four kinds of variations:
  • COutputCache::$varyByRoute: this specifies whether the cached content should be varied with the requested route (controller and action)
  • COutputCache::$varyByParam: this specifies a list of GET parameter names and uses the corresponding values to determine the version of the cached content.
  • COutputCache::$varyBySession: this specifies whether the cached content should be varied with the user session.
  • COutputCache::$varyByExpression: this specifies whether the cached content should be varied with the result of the specified PHP expression.
  • COutputCache::$varyByLanguage: this specifies whether the cached content should by varied with the user's language. Available since 1.1.14.
For more advanced variation, override COutputCache::getBaseCacheKey() method.
CComponent
Extended by CBaseController
Extended by CWidget
Extended by CFilterWidget implements IFilter
Extended by COutputCache
Package: system\web\widgets
Copyright: 2008-2013 Yii Software LLC
License: http://www.yiiframework.com/license/
Author: Qiang Xue <qiang.xue@gmail.com>
Since: 1.0
Located at x2engine/framework/web/widgets/COutputCache.php
Methods summary
public boolean
# filter( CFilterChain $filterChain )

Performs filtering before the action is executed. This method is meant to be overridden by child classes if begin-filtering is needed.

Performs filtering before the action is executed. This method is meant to be overridden by child classes if begin-filtering is needed.

Parameters

$filterChain
CFilterChain
$filterChain list of filters being applied to an action

Returns

boolean
whether the filtering process should stop after this filter. Defaults to false.

Overrides

CFilterWidget::filter()
public
# init( )

Marks the start of content to be cached. Content displayed after this method call and before CBaseController::endCache() will be captured and saved in cache. This method does nothing if valid content is already found in cache.

Marks the start of content to be cached. Content displayed after this method call and before CBaseController::endCache() will be captured and saved in cache. This method does nothing if valid content is already found in cache.

Overrides

CWidget::init()
public
# run( )

Marks the end of content to be cached. Content displayed before this method call and after COutputCache::init() will be captured and saved in cache. This method does nothing if valid content is already found in cache.

Marks the end of content to be cached. Content displayed before this method call and after COutputCache::init() will be captured and saved in cache. This method does nothing if valid content is already found in cache.

Overrides

CWidget::run()
public boolean
# getIsContentCached( )

Returns

boolean
whether the content can be found from cache
protected boolean
# checkContentCache( )

Looks for content in cache.

Looks for content in cache.

Returns

boolean
whether the content is found in cache.
protected ICache
# getCache( )

Returns

ICache
the cache used for caching the content.
protected string
# getBaseCacheKey( )

Caclulates the base cache key. The calculated key will be further variated in COutputCache::getCacheKey(). Derived classes may override this method if more variations are needed.

Caclulates the base cache key. The calculated key will be further variated in COutputCache::getCacheKey(). Derived classes may override this method if more variations are needed.

Returns

string
basic cache key without variations
protected string
# getCacheKey( )

Calculates the cache key. The key is calculated based on COutputCache::getBaseCacheKey() and other factors, including COutputCache::$varyByRoute, COutputCache::$varyByParam, COutputCache::$varyBySession and COutputCache::$varyByLanguage.

Calculates the cache key. The key is calculated based on COutputCache::getBaseCacheKey() and other factors, including COutputCache::$varyByRoute, COutputCache::$varyByParam, COutputCache::$varyBySession and COutputCache::$varyByLanguage.

Returns

string
cache key
public
# recordAction( string $context, string $method, array $params )

Records a method call when this output cache is in effect. When the content is served from the output cache, the recorded method will be re-invoked.

Records a method call when this output cache is in effect. When the content is served from the output cache, the recorded method will be re-invoked.

Parameters

$context
string
$context a property name of the controller. The property should refer to an object whose method is being recorded. If empty it means the controller itself.
$method
string
$method the method name
$params
array
$params parameters passed to the method
protected
# replayActions( )

Replays the recorded method calls.

Replays the recorded method calls.

Methods inherited from CFilterWidget
__construct(), getIsFilter()
Methods inherited from CWidget
actions(), getController(), getId(), getOwner(), getViewFile(), getViewPath(), render(), setId()
Methods inherited from CBaseController
beginCache(), beginClip(), beginContent(), beginWidget(), createWidget(), endCache(), endClip(), endContent(), endWidget(), renderFile(), renderInternal(), widget()
Methods inherited from CComponent
__call(), __get(), __isset(), __set(), __unset(), asa(), attachBehavior(), attachBehaviors(), attachEventHandler(), canGetProperty(), canSetProperty(), detachBehavior(), detachBehaviors(), detachEventHandler(), disableBehavior(), disableBehaviors(), enableBehavior(), enableBehaviors(), evaluateExpression(), getEventHandlers(), hasEvent(), hasEventHandler(), hasProperty(), raiseEvent()
Constants summary
string CACHE_KEY_PREFIX 'Yii.COutputCache.'
#

Prefix to the keys for storing cached data

Prefix to the keys for storing cached data

Properties summary
public integer $duration 60
#

number of seconds that the data can remain in cache. Defaults to 60 seconds. If it is 0, existing cached content would be removed from the cache. If it is a negative value, the cache will be disabled (any existing cached content will remain in the cache.)

Note, if cache dependency changes or cache space is limited, the data may be purged out of cache earlier.

number of seconds that the data can remain in cache. Defaults to 60 seconds. If it is 0, existing cached content would be removed from the cache. If it is a negative value, the cache will be disabled (any existing cached content will remain in the cache.)

Note, if cache dependency changes or cache space is limited, the data may be purged out of cache earlier.

public boolean $varyByRoute true
#

whether the content being cached should be differentiated according to route. A route consists of the requested controller ID and action ID. Defaults to true.

whether the content being cached should be differentiated according to route. A route consists of the requested controller ID and action ID. Defaults to true.

public boolean $varyBySession false
#

whether the content being cached should be differentiated according to user sessions. Defaults to false.

whether the content being cached should be differentiated according to user sessions. Defaults to false.

public array $varyByParam
#

list of GET parameters that should participate in cache key calculation. By setting this property, the output cache will use different cached data for each different set of GET parameter values.

list of GET parameters that should participate in cache key calculation. By setting this property, the output cache will use different cached data for each different set of GET parameter values.

public string $varyByExpression
#

a PHP expression whose result is used in the cache key calculation. By setting this property, the output cache will use different cached data for each different expression result. The expression can also be a valid PHP callback, including class method name (array(ClassName/Object, MethodName)), or anonymous function (PHP 5.3.0+). The function/method signature should be as follows:

function foo($cache) { ... }

where $cache refers to the output cache component.

The PHP expression will be evaluated using CComponent::evaluateExpression().

A PHP expression can be any PHP code that has a value. To learn more about what an expression is, please refer to the php manual.

a PHP expression whose result is used in the cache key calculation. By setting this property, the output cache will use different cached data for each different expression result. The expression can also be a valid PHP callback, including class method name (array(ClassName/Object, MethodName)), or anonymous function (PHP 5.3.0+). The function/method signature should be as follows:

function foo($cache) { ... }

where $cache refers to the output cache component.

The PHP expression will be evaluated using CComponent::evaluateExpression().

A PHP expression can be any PHP code that has a value. To learn more about what an expression is, please refer to the php manual.

public boolean $varyByLanguage false
#

whether the content being cached should be differentiated according to user's language. A language is retrieved via Yii::app()->language. Defaults to false.

whether the content being cached should be differentiated according to user's language. A language is retrieved via Yii::app()->language. Defaults to false.

Since

1.1.14
public array $requestTypes
#

list of request types (e.g. GET, POST) for which the cache should be enabled only. Defaults to null, meaning all request types.

list of request types (e.g. GET, POST) for which the cache should be enabled only. Defaults to null, meaning all request types.

public string $cacheID 'cache'
#

the ID of the cache application component. Defaults to 'cache' (the primary cache application component.)

the ID of the cache application component. Defaults to 'cache' (the primary cache application component.)

public mixed $dependency
#

the dependency that the cached content depends on. This can be either an object implementing ICacheDependency interface or an array specifying the configuration of the dependency object. For example,

array(
    'class'=>'CDbCacheDependency',
    'sql'=>'SELECT MAX(lastModified) FROM Post',
)

would make the output cache depends on the last modified time of all posts. If any post has its modification time changed, the cached content would be invalidated.

the dependency that the cached content depends on. This can be either an object implementing ICacheDependency interface or an array specifying the configuration of the dependency object. For example,

array(
    'class'=>'CDbCacheDependency',
    'sql'=>'SELECT MAX(lastModified) FROM Post',
)

would make the output cache depends on the last modified time of all posts. If any post has its modification time changed, the cached content would be invalidated.

Properties inherited from CFilterWidget
$stopAction
Properties inherited from CWidget
$actionPrefix, $skin
Magic properties summary
public boolean $isContentCached
#

Whether the content can be found from cache.

Whether the content can be found from cache.

Magic properties inherited from CFilterWidget
$isFilter
Magic properties inherited from CWidget
$controller, $id, $owner, $viewPath
API documentation generated by ApiGen 2.8.0