S
S
Snorway2016-07-07 10:29:31
Yii
Snorway, 2016-07-07 10:29:31

Yii2 why data is not written to cache?

Added to the components section:

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

A simple example of the form does not work:
$data = \Yii::$app->cache->get('key_name');
if ($data === false) {
    $a = \Yii::$app->cache->add('key_name', "value", 60);
}

In this example, $a always returns true, but $data is always false. There is silence in PHP and Yii2 logs. Folders with files are created in the runtime/cache folder. What could be the problem?
UPDATE: Problem solved, answer below.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Snorway, 2016-07-07
@Snorway

The problem was in synchronizing the files of the guest machine with the host. Under this case, vagrant-winnfsd was installed in Vagrant. Demolished the plugin, everything is in order.

A
Andrew, 2016-07-07
@ApXaHgheJI


// add()	Stores a value identified by a key into cache if the cache does not contain this key.
$a = \Yii::$app->cache->add('key_name', "value", 60);

Why not use the SET method - it doesn't look at anything - it just creates a key/value.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question