yii2: http caching always return status 200

What steps will reproduce the problem?

use http cache etag
[
                'class' => 'yii\filters\HttpCache',
                'only' => ['show', 'pdf', 'show-video', 'show-doc'],
                'etagSeed' => function ($action, $params) {
                    $file = UploadedFile::findOne(['id' => \Yii::$app->request->get('id')]);
                    if($file){
                        return serialize([$file->id, $file->created_at]);
                    }
                },
                'sessionCacheLimiter' => 'public',
            ],

What's expected?

Next request should cache return http status 304(not modified)

What do you get instead?

Screen Shot 2020-11-09 at 15 49 55

return http status 200 each request

Additional info

Q A
Yii version 2.0.38
PHP version 7.3
Web Server Apche 2.4.6 http 1.1
Operating system Centos 7

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 19 (10 by maintainers)

Most upvoted comments

I cannot reproduce your case. I told you what might be a reason based on the code flow. I have found this issue - maybe this is the reason.

echo automatically makes PHP to send headers. After that, no more headers could be sent including ETag.