Http Caching Problem

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?!

Thanks

Another consideration. I deactivate the cache from the configuration. If i use CHttpCacheFilter for some action within controllers it works anyway!

How it works? Where should i find the cache file? The cache directory is empty!

No help guys?

CHttpCacheFilter cannot be deactivated from application configuration. It’s an action filter. You have to remove it from filters() to disable it.

There’s no cache file for CHttpCacheFilter. It controls client side caching via HTTP response headers.

Sorry, this has been a bit under my radar.

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.

So, to really cache a page i should use COutputCache?

What’s giving you that idea?

http://www.yiiframework.com/doc/guide/1.1/it/caching.page

Aha? I wrote half of that page and don’t see your argument …

So, am i wrong?

I don’t know what your conclusions are so I can’t possibly say.

I just want to understand if COutputCache is the real way to cache "classically" a whole page.

I am in the same situation, i am trying [size="2"]COutputCache.[/size]

Is it a good solution according to you ?

Thank for your answer

<br style="font-size: 9pt;">[size="2"]

I had the same problem, the browser returned ‘(from-cache)’ even if my page changed. It only works when I clicked the refresh button or F5.

The must-revalidate works for me, now I get the fresh page without clicking the refresh.

Da:Sourcerer, thank you! You saved me a lot of time.