public function flush() { $this->connect(); $res = $this->cache->flush(); if ($res === false) { $this->logger->writeError("failed to flush memcache server[" . implode(',', $this->host) . "]."); } if ($this->logger->isDebugEnabled()) { $this->logger->writeDebug("[flush]"); } return $res; }
protected function getSQL($sql, $params = null) { $format_sql = $sql; if (is_array($params)) { $format_sql = vsprintf($sql, $params); } elseif (!is_null($params)) { $format_sql = sprintf($sql, $params); } if ($format_sql === false) { $this->logger->writeError("the composit sql is false, check it:[sql={$sql}, param={$params}]"); } if ($this->logger->isDebugEnabled()) { $this->logger->writeDebug("trying to exectue sql[db_helper=%s,host=%s,db=%s] : %s", array(spl_object_hash($this), $this->config['host'], $this->config['database'], $format_sql)); } return $format_sql; }
protected function deleteFromCache() { switch ($this->cache_type) { case self::CACHE_KEY_LIST: $cache = $this->getCacheInstance(); $cache_list_key = $this->getListCacheKey(); $cached_list = $cache->get($cache_list_key); foreach ($cached_list as $cached_entry) { $cache->delete($this->getTableMemkey($cached_entry)); } $cache->delete($cache_list_key); break; case self::CACHE_IN_LIST: case self::CACHE_PRIMARY_KEY: $cache = $this->getCacheInstance(); $deleted_vals = array(); if ($this->affected_rows <= 1) { $primary_key = $this->getPrimaryKey(); $deleted_vals[] = array_intersect_key($this->keys, $primary_key); } else { $primary_key = $this->getPrimaryKey(); foreach ($this->keys as $field => $val) { $fields = explode(",", $field); if (count($fields) > 1) { if ($fields != array_keys($primary_key)) { continue; } foreach ($val as $v) { $arr = array_combine($fields, $v); if ($arr === false) { continue; } $deleted_vals[] = $arr; } } else { if (array($field) != array_keys($primary_key)) { continue; } if (is_array($val)) { foreach ($val as $v) { $deleted_vals[] = array($field => $v); } } else { $deleted_vals[] = array($field => $v); } } } } foreach ($deleted_vals as $deleted_val) { $cache->delete($this->getTableMemkey($deleted_val)); } // 将相应的cache_list里边的元素删除掉 $cached_list_key = $this->getListCacheKey(); $cached_list = $cache->get($cached_list_key); foreach ($deleted_vals as $deleted_val) { foreach ($cached_list as $k => $v) { if ($v == $deleted_val) { unset($cached_list[$k]); } } } if (empty($cached_list)) { if ($this->logger->isDebugEnabled()) { $this->logger->writeDebug("[deleteFromCache]tring to delete list cache[key={$cache_list_key}]"); } $cache->delete($cached_list_key); } else { if ($this->logger->isDebugEnabled()) { $this->logger->writeDebug("tring to delete item in list cache[key={$cached_list_key},value=" . print_r($cached_list, true) . "]"); } $cache->set($cached_list_key, $cached_list, 0); } break; } }