I’ve a table with different records, each one with an attribute “ultima_modifica” (datetime mysql type) that is reguarly updated each time i update a record.
I’m trying to use Http Caching. It chaches the page correctly, but when i update the record, the cache will be refreshed only if i manually refresh the page (pushing f5 on the page, for instance). It is not updated when i click on the proper link within the grid to access the same page.
This is my "filters" method:
public function filters() {
return array(
array(
'CHttpCacheFilter + view + dettaglio',
'lastModified'=>Yii::app()->db->createCommand("SELECT MAX(`ultima_modifica`) FROM bilanci")->queryScalar(),
),
'accessControl', // perform access control for CRUD operations
'postOnly + delete', // we only allow deletion via POST request
);
}
If i use {{bilanci}}, Yii raise an error. So i’ve to change it to “bilanci” (name of the table), and i works like said up to this post.
How should i use it? Is the query correct?
My doubt is: shouldn’t i use a query like “Select ‘ultima_modifica’ from bilanci where id = {id}”? How the cache will recognize the specific last_update of a record without specifing it’s id?!
Can happen if your browser decides that clicking on that link counts as “skipping through the browser history.” In that case, http caching headers aren’t involved much. You can try to alter this by adding [font=“Courier New”]must-revalidate[/font] to CHttpCacheFilter.cacheControl.
Sort of. This will invalidate the hhtp cache for all affected pages if one is being updated. Could do better, though.
You can use lastModifiedExpression instead. You should be able to get the id through [font=“Courier New”]Yii::app()->getRequest()->getParam(‘id’)[/font].
CHttpCacheFilter works without creating any cache files. It’s solely operating on HTTP headers. Quite possibly your browser decided those were still valid. If you are on Firefox: You can always hit <ctrl>+<f5> to reload a page without any caching headers having a say.