SoFunction
Updated on 2025-03-10

Example of basic usage of yii2 cache Caching

This article describes the basic usage of yii2 cache Caching. Share it for your reference, as follows:

Add in yii's configuration file:

'cache' => [
  'class' => 'yii\caching\ApcCache',
],

Cache usage:

<?php
$key = 'cacheKey';
//Read cache$data = Yii::$app->cache->get($key);
//Judge whether the cache exists, and if it does not exist, a cache will be generatedif ($data === false) {
$cache->set($key, $data);
}
?>

For more information about Yii, readers who are interested in this site can view the topic:Yii framework introduction and common techniques summary》、《Summary of excellent development framework for php》、《Basic tutorial on getting started with smarty templates》、《PHP object-oriented programming tutorial》、《Summary of usage of php strings》、《PHP+mysql database operation tutorial"and"Summary of common database operation techniques for php

I hope that this article will be helpful to everyone's PHP programming based on the Yii framework.