Home  >  Article  >  PHP Framework  >  What cache is used for yii2 user login?

What cache is used for yii2 user login?

爱喝马黛茶的安东尼
爱喝马黛茶的安东尼Original
2019-12-09 11:39:052115browse

What cache is used for yii2 user login?

In the face of some data that does not change too much in a short period of time and requires time-consuming calculations, cache is often used

[DataCache]

In Configuration under the components item in the configuration file main.php

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

\Yii::$app->cache->set('test',$data);//Save, the type can be string, array Wait

\Yii::$app->cache->get('test');//Get, if there is no such value, return bool(false), if so, return the value Value

The cache file will find a folder called te (the first two letters of the key name test) in the runtime\cache directory, where test.bin is the cache file of the data.

In addition to set and get, there are several methods:

What cache is used for yii2 user login?

If you want to change the caching method to DbCache, modify the components item in main.php The following configuration is:

'cache' => [
    'class' => 'yii\caching\DbCache',
    'db' => 'mydb',
    'cacheTable' => 'my_cache',
],

PHP Chinese website, there are a large number of free Yii introductory tutorials, everyone is welcome to learn!

The above is the detailed content of What cache is used for yii2 user login?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn