PHP Класс yii\filters\HttpCache

It is an action filter that can be added to a controller and handles the beforeAction event. To use HttpCache, declare it in the behaviors() method of your controller class. In the following example the filter will be applied to the list-action and the Last-Modified header will contain the date of the last update to the user table in the database. php public function behaviors() { return [ [ 'class' => 'yii\filters\HttpCache', 'only' => ['index'], 'lastModified' => function ($action, $params) { $q = new \yii\db\Query(); return $q->from('user')->max('updated_at'); }, 'etagSeed' => function ($action, $params) { return // generate ETag seed here } ], ]; }
С версии: 2.0
Автор: Da:Sourcerer ([email protected])
Автор: Qiang Xue ([email protected])
Наследование: extends yii\base\ActionFilter
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$cacheControlHeader the value of the Cache-Control HTTP header. If null, the header will not be sent.
$enabled a value indicating whether this filter should be enabled.
$etagSeed a PHP callback that generates the ETag seed string. The callback's signature should be: php function ($action, $params) where $action is the [[Action]] object that this filter is currently handling; $params takes the value of [[params]]. The callback should return a string serving as the seed for generating an ETag.
$lastModified a PHP callback that returns the UNIX timestamp of the last modification time. The callback's signature should be: php function ($action, $params) where $action is the [[Action]] object that this filter is currently handling; $params takes the value of [[params]]. The callback should return a UNIX timestamp.
$params additional parameters that should be passed to the [[lastModified]] and [[etagSeed]] callbacks.
$sessionCacheLimiter the name of the cache limiter to be set when session_cache_limiter() is called. The default value is an empty string, meaning turning off automatic sending of cache headers entirely. You may set this property to be public, private, private_no_expire, and nocache. Please refer to session_cache_limiter() for detailed explanation of these values. If this property is null, then session_cache_limiter() will not be called. As a result, PHP will send headers according to the session.cache_limiter PHP ini setting.
$weakEtag whether to generate weak ETags. Weak ETags should be used if the content should be considered semantically equivalent, but not byte-equal.

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

Метод Описание
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.

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

Метод Описание
generateEtag ( string $seed ) : string Generates an ETag from the given seed string.
sendCacheControlHeader ( ) Sends the cache control header to the client
validateCache ( integer $lastModified, string $etag ) : boolean Validates if the HTTP cache contains valid content.

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

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.

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

Generates an ETag from the given seed string.
protected generateEtag ( string $seed ) : string
$seed string Seed for the ETag
Результат string the generated ETag

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

Sends the cache control header to the client
См. также: cacheControlHeader
protected sendCacheControlHeader ( )

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

If both Last-Modified and ETag are null, returns false.
protected validateCache ( integer $lastModified, string $etag ) : boolean
$lastModified integer the calculated Last-Modified value in terms of a UNIX timestamp. If null, the Last-Modified header will not be validated.
$etag string the calculated ETag value. If null, the ETag header will not be validated.
Результат boolean whether the HTTP cache is still valid.

Описание свойств

$cacheControlHeader публичное свойство

the value of the Cache-Control HTTP header. If null, the header will not be sent.
См. также: http://tools.ietf.org/html/rfc2616#section-14.9
public $cacheControlHeader

$enabled публичное свойство

a value indicating whether this filter should be enabled.
public $enabled

$etagSeed публичное свойство

a PHP callback that generates the ETag seed string. The callback's signature should be: php function ($action, $params) where $action is the [[Action]] object that this filter is currently handling; $params takes the value of [[params]]. The callback should return a string serving as the seed for generating an ETag.
public $etagSeed

$lastModified публичное свойство

a PHP callback that returns the UNIX timestamp of the last modification time. The callback's signature should be: php function ($action, $params) where $action is the [[Action]] object that this filter is currently handling; $params takes the value of [[params]]. The callback should return a UNIX timestamp.
См. также: http://tools.ietf.org/html/rfc7232#section-2.2
public $lastModified

$params публичное свойство

additional parameters that should be passed to the [[lastModified]] and [[etagSeed]] callbacks.
public $params

$sessionCacheLimiter публичное свойство

the name of the cache limiter to be set when session_cache_limiter() is called. The default value is an empty string, meaning turning off automatic sending of cache headers entirely. You may set this property to be public, private, private_no_expire, and nocache. Please refer to session_cache_limiter() for detailed explanation of these values. If this property is null, then session_cache_limiter() will not be called. As a result, PHP will send headers according to the session.cache_limiter PHP ini setting.
public $sessionCacheLimiter

$weakEtag публичное свойство

whether to generate weak ETags. Weak ETags should be used if the content should be considered semantically equivalent, but not byte-equal.
См. также: http://tools.ietf.org/html/rfc7232#section-2.3
С версии: 2.0.8
public $weakEtag