As long as PHP programs continue being scripts to launch, output the results, and then die, the idea of caching results of computations is used. The mathematical concept of memoization, implemented at the level of a language runtime environment, is used extensively in the PHP ecosystem, and the Yii framework supports a wide range of caching techniques to speed up your program.

There are four levels of caching in Yii 2, which are as follows:

  • The database queries cache
  • The HTML page fragments cache
  • The whole request cache
  • The HTML response cache with the help of some HTTP headers

Before we look at all of these features in turn, we need to understand that there’s a cache component inside the Yii 2 framework that is the heart of the caching functionality.