/** * 重写set方法,在设置缓存的时候 * @see \yii\caching\Cache::set() */ public function set($key, $value, $duration = 0, $dependency = null) { if (!$this->isDisableCache()) { $a = parent::set($key, $value, $duration, $dependency); if (!$a) { if ($this->useMemcached) { $msg = $this->getMemcache()->getResultMessage(); $code = $this->getMemcache()->getResultCode(); $keytmp = $this->buildKey($key); file_put_contents('/tmp/mycache.log', date("Y-m-d H:i:s", time()) . json_encode($key) . " key {$keytmp} set fail \r\n", FILE_APPEND); file_put_contents('/tmp/mycache.log', date("Y-m-d H:i:s", time()) . "code :{$code}, msg: {$msg} \r\n", FILE_APPEND); } } \Yii::$app->slavecache->set($key, $value, $duration, $dependency); return $a; } return false; }
/** * 重写set方法,在设置缓存的时候,进行规则校验并插入存储的key,注意这里key-rule的长度不用超过100 * @see \yii\caching\Cache::set() */ public function set($key, $value, $duration = 0, $dependency = null) { CacheVisitLogService::put(CacheVisitLogService::DO_SET, $key, $value); if (!$this->isDisableCache() && $this->findKeyRule($key)) { $a = parent::set($key, $value, $duration, $dependency); if (!$a) { if ($this->useMemcached) { $msg = $this->getMemcache()->getResultMessage(); $code = $this->getMemcache()->getResultCode(); $keytmp = $this->buildKey($key); file_put_contents('/tmp/mycache.log', date("Y-m-d H:i:s", time()) . json_encode($key) . " key {$keytmp} set fail \r\n", FILE_APPEND); file_put_contents('/tmp/mycache.log', date("Y-m-d H:i:s", time()) . "code :{$code}, msg: {$msg} \r\n", FILE_APPEND); } } \Yii::$app->slavecache->set($key, $value, $duration, $dependency); // if($a) { // $sql = 'insert ignore into `cache_key_list` ( `cache_key_rule`, `key` , `create_time`) values (:CKR,:K,:CT)'; // DB('config')->createCommand($sql,[':CKR'=>$key[0],':K'=>$this->keyPrefix.$this->buildKeyByRule($key),':CT'=>date('Y-m-d H:i:s')])->execute(); // return true; // } return $a; } return false; }
/** * 重写set方法,在设置缓存的时候,进行规则校验并插入存储的key,注意这里key-rule的长度不用超过100 * @see \yii\caching\Cache::set() */ public function set($key, $value, $duration = 0, $dependency = null) { if ($this->findKeyRule($key)) { $a = parent::set($key, $value, $duration, $dependency); // if($a) { // $sql = 'insert ignore into `cache_key_list` ( `cache_key_rule`, `key` , `create_time`) values (:CKR,:K,:CT)'; // DB('config')->createCommand($sql,[':CKR'=>$key[0],':K'=>$this->keyPrefix.$this->buildKeyByRule($key),':CT'=>date('Y-m-d H:i:s')])->execute(); // return true; // } return $a; } return false; }