Etags should be generated based only on data, that is collections and single records.
There can be many strategies for generating etags, like:
hash pk and version
hash pk and last modified time if version is not available
hash all attributes
store hash and update it using a db trigger or app event
Hashing a collection always requires iterating over it, so when streaming is used cache should be disabled anyway - that duplicates streaming conditions.
Caching should be disabled if the response contains metadata like:
action links, including disabled ones after checking auth
main menu or other nav items with "hot items" indicators (counters)
This usually happens when response format is html and whole page is loaded (pjax is not used). Additional filters in HttpCache could help use caching for page fragments.
Add the following behavior in the \netis\crud\ActiveController class:
[
'class' => 'yii\filters\HttpCache',
'only' => ['index', 'relation', 'view'],
'lastModified' => function ($action, $params) {
$q = new \yii\db\Query();
return $q->from('user')->max('updated_at');
},
'etagSeed' => function ($action, $params) {
/**
* use pk + version, pk + last timestamp or serialize whole record
* this should also include changes to the user state, like auth
*/
return // generate etag seed here
},
],
Etags should be generated based only on data, that is collections and single records.
There can be many strategies for generating etags, like:
Hashing a collection always requires iterating over it, so when streaming is used cache should be disabled anyway - that duplicates streaming conditions.
Caching should be disabled if the response contains metadata like:
This usually happens when response format is html and whole page is loaded (pjax is not used). Additional filters in
HttpCache
could help use caching for page fragments.Add the following behavior in the
\netis\crud\ActiveController
class: