tareq
tareq

Reputation: 1129

caching a value using memcache in yii2

I followed the documentation and configured my config/main.php as they stated.

now i try to access the memcache object as the following

Yii::$app->cache->Memcache->add('12', '12');

and get the value as the following

Yii::$app->cache->Memcache->get('12')

i don't get anything in the network section in chrome's inspect element feature for a few seconds and then i get this error:

"MemcachePool::add(): php_network_getaddresses: getaddrinfo failed: Name or service not known'"

Upvotes: 2

Views: 4784

Answers (2)

raiym
raiym

Reputation: 1499

Here is the example from my project.

    $key = 'my_key';
    $employees = \Yii::$app->cache->get($key);
    if ($employees === false) {
        $employees = Employee::findBySql('some sql statement')->all();
        \Yii::$app->cache->set($key, $employees, 43200); // time in seconds to store cache
    }

Upvotes: 6

tareq
tareq

Reputation: 1129

ok it was a small configuration error, i forgot to set the host as localhost -__-

Upvotes: 0

Related Questions