yii2学习笔记 --- memcache保存缓存不成功

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/weixin_41120504/article/details/89178014

打开配置文件跟踪memcache缓存代码

基础版 config\web.php  

'memcache' => [
            'class' => '\yii\caching\MemCache',
            'useMemcached'=>false,
            'servers' => [
                [
                    'host' => '127.0.0.1',
                    'port' => 11211,
                    'weight' => 100,
                ],
            ],
        ],

跟踪到文件vendor\yiisoft\yii2\caching\MemCache.php

找到 setValue()方法 约293行 改为下面代码

protected function setValue($key, $value, $duration)
    {
        // Use UNIX timestamp since it doesn't have any limitation
        // @see https://secure.php.net/manual/en/memcache.set.php
        // @see https://secure.php.net/manual/en/memcached.expiration.php
        $expire = $duration > 0 ? $duration + time() : 0;

        return $this->useMemcached ? $this->_cache->set($key, $value, $expire) : $this->_cache->set($key, $value, 0, $duration);
        //return $this->useMemcached ? $this->_cache->set($key, $value, $expire) : $this->_cache->set($key, $value, 0, $expire);
    }

猜你喜欢

转载自blog.csdn.net/weixin_41120504/article/details/89178014