Cache question


this is a question about page cache.

For example if I set a dependency:

‘dependency’ => [

            'class' => 'yii\caching\DbDependency',

            'sql' => 'SELECT COUNT(*) FROM post',
  1. How exactly does Yii knows when to refresh that page cache ? Does it store the ‘count’ somewhere, and run the query to compare on each page request ?

  2. Is it possible to delete a specific page cache value (set by yii automatically) based on its key ?

  3. Does a cached page short circuit controler processing ? For example, if a cached page is loaded, are all the db queries from the controller skipped ?

Yii stores the cache content indexed by its "key" in the cache media. And it also stores the dependency specification (in your case the SQL to get the count) and the result of it (the count) with the content itself.

When it is accessed the next time, Yii checks the duration of the cache, and executes the dependency check. If everything is OK, then the cached content will be served.

I think you can select an appropriate "key" and/or "variation" for the page that you want to handle differently.

As far as I know, yes. :)