F
F
fsanday2017-05-11 17:15:30
Yii
fsanday, 2017-05-11 17:15:30

Doesn't save in yii2 cache?

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;

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
fsanday, 2017-05-12
@fsanday

bool(false).
There is a suspicion that I have some settings for filecache missing. Can you suggest where to dig?

M
Maxim Timofeev, 2017-05-11
@webinar

You have a strange example, it should not work, try like this:

$cache = \Yii::$app->cache;
$t = $cache->get('name');
if ($t === false) {
    $t = 'some string';
    $cache->set('name', $t);
}
var_dump($t)

You have a part:
Accordingly $t, you will have a boolean, where do you get data from the cache? You, if there is a cache, take it, and if not, you set it, but after setting the cache, you need to drive it into the $t variable. To see something.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question