HttpCache active but yii debuger has executed database queries

Hi,

Is it normal behavior when the HttpCache is active the Yii Debugger still indicates Yii executed database queries?

The behaviors method in my controller looks like:




public function behaviors()

    {

        return [

            'verbs' => [

                'class' => VerbFilter::className(),

                'actions' => [

                    'delete' => ['POST'],

                ],

            ],

            [

                'class' => 'yii\filters\HttpCache',

                'only' => ['view'],

                'lastModified' => function ($action, $params) {

                    $q = new \yii\db\Query();

                    return strtotime($q->from('Extension')->where(['id' => $_GET['id']]) ->max('UpdatedAt'));

                },

//            'etagSeed' => function ($action, $params) {

//                return // generate ETag seed here

//            }

            ],

        ];

    }



When I navigate to my view page the HTTP status is 304, which is as expected.

Image -> image.prntscr.com/image/f59787f6db0a46a2ac01b2b27faf9e7b.png

But I would expect that the Yii Debugger won’t execute a Database Query, while he still executes all queries.

Image -> image.prntscr.com/image/44f2dccf41854523bb9c43f8060c4014.png

| Q | A

| ---------------- | —

| Yii version | 2.0.10

| PHP version | 5.6.25

| Operating system | Windows 10

|Apache | Apache/2.4.23 (Win64) PHP/5.6.25

HttpCache is only client-side. If the request comes in, Yii deals with it without caching.

You might want page-caching: http://www.yiiframework.com/doc-2.0/guide-caching-page.html

At the moment it doesn’t seems logic to me.

If this post is correct (source: http://stackoverflow.com/a/20978279/1080372)

As the server knows when to return a HTTP status 304 (Not Modified), why does he still deals with the request?

The website in development won’t have a huge amount of users, nearly a handful users on a day.

So page caching won’t improve the performance drastically.

I hope my conclusion about page caching is correct?

You may be getting a cached response along with Yii Debugger output. Check if there’s actual query made.

Hi,

Indeed!

It must be caching.

Did my tests again with ‘Neor Profile SQL’

When pressing ‘F5’ on the page, Yii executes two queries.

When pressing ‘SHIFT’ + ‘F5’ all database queries are executed.

Thanks!

The caching mechanism works as expected.