Cache issue - Refresh page to see modified content

Hi,
I’m using FileCache in my cache component.
In my controller, I’m using :
[
‘class’ => ‘yii\filters\HttpCache’,
‘only’ => [‘view’],
‘etagSeed’ => function ($action, $params) {
$model = $this->findModel(Yii::$app->request->get(‘id’));
return $model->update_time;
},
],

The cache works well with yii\filters\PageCache and yii\filters\HttpCache. But when the cache is invalidated, I still see the cached content untill I refresh the browser (F5).
I know this can be a standard browser behavior for caching. But how can I see the new content without refreshing each time the browser to get the last content ?

Hi @samirmember1, welcome to the forum.

Just as you have noticed, this is an issue with the client-side cache (namely ‘browser cache’ or ‘http cache’) rather than the server-side cache for which FileCache and others are provided.

Please take a look at the guide > Caching > Http Caching
https://www.yiiframework.com/doc/guide/2.0/en/caching-http

Hello @softark

Thanks for your response.

But in this case, how can I solve this issue ? In the browser side ? Is there any best practice for this client-side cache so that I can always get the last data from my cached pages using FileCache ?

I think you have to re-consider the logic of generating ETag. Is it enough for you to check the updated time?

Hi @softark,
This was just for a simplicity purpose. In fact i’m using a more complex check to invalidate the cache in the etagSeed.
But my only peoblem is how to deal with the client side cache without having to refresh (F5) each time the browser when i have to check for a new data.

Hmm…

Do you want to refresh the page content without user action while the user is viewing the page when the content is modified in the server side, just as twitter-like apps are doing time to time?

Or, in other words, do you get the modified latest content when you come to the target page from other page? Or do you have to push F5 to get the latest content even in such a case?

Second option: When i’m visiting the target page from other page, I’m getting the old content. But when I push F5, the page refresh with the last content.
I’ve checked the Etag value on my GET request in the browser, and I’ve found that i’m getting the old Etag value until I refresh the page using the F5 button.
Am I missing something ?

I agree that this is very strange. It completely breaks the concept of ETag.
I’m sorry I don’t understand what’s going on. I may be missing something, too.

Thanks for your response @softark
Does anyone already faced this issue and has a solution ?