PHP 클래스 yii\filters\PageCache

It is an action filter that can be added to a controller and handles the beforeAction event. To use PageCache, declare it in the behaviors() method of your controller class. In the following example the filter will be applied to the index action and cache the whole page for maximum 60 seconds or until the count of entries in the post table changes. It also stores different versions of the page depending on the application language. php public function behaviors() { return [ 'pageCache' => [ 'class' => 'yii\filters\PageCache', 'only' => ['index'], 'duration' => 60, 'dependency' => [ 'class' => 'yii\caching\DbDependency', 'sql' => 'SELECT COUNT(*) FROM post', ], 'variations' => [ \Yii::$app->language, ] ], ]; }
부터: 2.0
저자: Qiang Xue ([email protected])
상속: extends yii\base\ActionFilter
파일 보기 프로젝트 열기: yiisoft/yii2 1 사용 예제들

공개 프로퍼티들

프로퍼티 타입 설명
$cache the cache object or the application component ID of the cache object. After the PageCache object is created, if you want to change this property, you should only assign it with a cache object. Starting from version 2.0.2, this can also be a configuration array for creating the object.
$cacheCookies a boolean value indicating whether to cache all cookies, or an array of cookie names indicating which cookies can be cached. Be very careful with caching cookies, because it may leak sensitive or private data stored in cookies to unwanted users.
$cacheHeaders a boolean value indicating whether to cache all HTTP headers, or an array of HTTP header names (case-insensitive) indicating which HTTP headers can be cached. Note if your HTTP headers contain sensitive information, you should white-list which headers can be cached.
$dependency the dependency that the cached content depends on. This can be either a [[Dependency]] object or a configuration array for creating the dependency object. For example, php [ 'class' => 'yii\caching\DbDependency', 'sql' => 'SELECT MAX(updated_at) FROM post', ] would make the output cache depend on the last modified time of all posts. If any post has its modification time changed, the cached content would be invalidated. If [[cacheCookies]] or [[cacheHeaders]] is enabled, then [[\yii\caching\Dependency::reusable]] should be enabled as well to save performance. This is because the cookies and headers are currently stored separately from the actual page content, causing the dependency to be evaluated twice.
$duration number of seconds that the data can remain valid in cache. Use 0 to indicate that the cached data will never expire.
$enabled whether to enable the page cache. You may use this property to turn on and off the page cache according to specific setting (e.g. enable page cache only for GET requests).
$variations list of factors that would cause the variation of the content being cached. Each factor is a string representing a variation (e.g. the language, a GET parameter). The following variation setting will cause the content to be cached in different versions according to the current application language: php [ Yii::$app->language, ]
$varyByRoute whether the content being cached should be differentiated according to the route. A route consists of the requested controller ID and action ID. Defaults to true.
$view the view component to use for caching. If not set, the default application view component [[\yii\web\Application::view]] will be used.

공개 메소드들

메소드 설명
beforeAction ( Action $action ) : boolean This method is invoked right before an action is to be executed (after all possible filters.) You may override this method to do last-minute preparation for the action.
cacheResponse ( ) Caches response properties.
init ( )

보호된 메소드들

메소드 설명
calculateCacheKey ( ) : array
restoreResponse ( Response $response, array $data ) Restores response properties from the given data

메소드 상세

beforeAction() 공개 메소드

This method is invoked right before an action is to be executed (after all possible filters.) You may override this method to do last-minute preparation for the action.
public beforeAction ( Action $action ) : boolean
$action yii\base\Action the action to be executed.
리턴 boolean whether the action should continue to be executed.

cacheResponse() 공개 메소드

Caches response properties.
부터: 2.0.3
public cacheResponse ( )

calculateCacheKey() 보호된 메소드

부터: 2.0.3
protected calculateCacheKey ( ) : array
리턴 array the key used to cache response properties.

init() 공개 메소드

public init ( )

restoreResponse() 보호된 메소드

Restores response properties from the given data
부터: 2.0.3
protected restoreResponse ( Response $response, array $data )
$response yii\web\Response the response to be restored
$data array the response property data

프로퍼티 상세

$cache 공개적으로 프로퍼티

the cache object or the application component ID of the cache object. After the PageCache object is created, if you want to change this property, you should only assign it with a cache object. Starting from version 2.0.2, this can also be a configuration array for creating the object.
public $cache

$cacheCookies 공개적으로 프로퍼티

a boolean value indicating whether to cache all cookies, or an array of cookie names indicating which cookies can be cached. Be very careful with caching cookies, because it may leak sensitive or private data stored in cookies to unwanted users.
부터: 2.0.4
public $cacheCookies

$cacheHeaders 공개적으로 프로퍼티

a boolean value indicating whether to cache all HTTP headers, or an array of HTTP header names (case-insensitive) indicating which HTTP headers can be cached. Note if your HTTP headers contain sensitive information, you should white-list which headers can be cached.
부터: 2.0.4
public $cacheHeaders

$dependency 공개적으로 프로퍼티

the dependency that the cached content depends on. This can be either a [[Dependency]] object or a configuration array for creating the dependency object. For example, php [ 'class' => 'yii\caching\DbDependency', 'sql' => 'SELECT MAX(updated_at) FROM post', ] would make the output cache depend on the last modified time of all posts. If any post has its modification time changed, the cached content would be invalidated. If [[cacheCookies]] or [[cacheHeaders]] is enabled, then [[\yii\caching\Dependency::reusable]] should be enabled as well to save performance. This is because the cookies and headers are currently stored separately from the actual page content, causing the dependency to be evaluated twice.
public $dependency

$duration 공개적으로 프로퍼티

number of seconds that the data can remain valid in cache. Use 0 to indicate that the cached data will never expire.
public $duration

$enabled 공개적으로 프로퍼티

whether to enable the page cache. You may use this property to turn on and off the page cache according to specific setting (e.g. enable page cache only for GET requests).
public $enabled

$variations 공개적으로 프로퍼티

list of factors that would cause the variation of the content being cached. Each factor is a string representing a variation (e.g. the language, a GET parameter). The following variation setting will cause the content to be cached in different versions according to the current application language: php [ Yii::$app->language, ]
public $variations

$varyByRoute 공개적으로 프로퍼티

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

$view 공개적으로 프로퍼티

the view component to use for caching. If not set, the default application view component [[\yii\web\Application::view]] will be used.
public $view