Not caches yii2?

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


controller:
if(Yii::$app-> cache-> exists('name'))
 $t = Yii::$app-> cache-> get('name');
else
 $t = Yii::$app->cache->set('name', '1234566788');


var_dump($t) = NULL;
June 26th 19 at 14:06
2 answers
June 26th 19 at 14:08
Solution
bool(false).
There is a suspicion that I have some settings for filecache missing. Can prompt where to dig?
and I noticed that filecache works when launch controllers from under the console, and the site is not working. In both configs prescribed
'cache' => [
 'class' => 'yii\caching\FileCache',]
- nikita.Stracke commented on June 26th 19 at 14:11
the problem was the rights on the folder where you created the cache data.
The folder rights were from one user, and run this application from another user. - nikita.Stracke commented on June 26th 19 at 14:14
June 26th 19 at 14:10
Strange example You have, it should not work, so try:
$cache = \Yii::$app->cache;
$t = $cache->get('name');
if ($t === false) {
 $t = 'some string';
 $cache->set('name', $t);
}
var_dump($t)

You have the part:
$t = Yii::$app->cache->set('name', '1234566788');
Respectively $t You will have a boolean, where do You get the data from the cache? You if the cache is take it, and if not - ask, but after setting the cache, it is necessary to drive it in the variable $t. That would be something to see.

Find more questions by tags Yii