Using cache dependencies and chains

Yii supports many cache backends, but what really makes the Yii cache flexible is the dependency and dependency chaining support. There are situations when you cannot simply cache data for an hour because the information cached can be changed at any time.

In this recipe, we will see how to cache a whole page and still always get fresh data when it is updated. The page will be of the dashboard-type and will show the five latest articles added and a total calculated for an account.

Note

Note that an operation cannot be edited as it is added, but an article can be.

Getting ready

Create a new yii2-app-basic application using the Composer package manager, as described in the official guide at http://www.yiiframework.com/doc-2.0/guide-start-installation.html ...

Get Yii2 Application Development Cookbook - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.