Caching behaviour not invalidating cache

Hi,

I’m attempting to run either HttpCache or PageCache against a given action, now, I’m able to get it working without a behaviour; in that it does the cache the page successfully, but in my case I need a behaviour to invalidate the cache depending on whether or not content has been added / updated.

I’ve setup APCu cache and I can see that it’s running as intended so I don’t suspect there to be any issue there. I’ve followed through the docs / forums and I just can’t seem to find an answer on what’s happening here.

Here is my code:

            [
                'class' => 'yii\filters\HttpCache',
                'only' => ['index'],
                'lastModified' => function ($action, $params) {
                    $q = new \yii\db\Query();
                    return $q->from('distribution_event')->max('updated_at');
                },
                'sessionCacheLimiter' => 'public',
            ],
            [
                'class' => 'yii\filters\PageCache',
                'only' => ['index'],
                'duration' => 3600,
                'dependency' => [
                    'class' => 'yii\caching\DbDependency',
                    'sql' => 'SELECT MAX(updated_at) FROM distribution_event',
                ],
            ],

Just a note: I’m not using these caching methods simultaneously, I’m just attempting one at a time.