mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 23:22:48 +08:00
改进使用了手动参数绑定的时候 缓存出现问题的情况
This commit is contained in:
@@ -401,7 +401,7 @@ class Query
|
|||||||
if (empty($this->options['table'])) {
|
if (empty($this->options['table'])) {
|
||||||
$this->options['table'] = $this->getTable();
|
$this->options['table'] = $this->getTable();
|
||||||
}
|
}
|
||||||
$key = is_string($cache['key']) ? $cache['key'] : md5($field . serialize($this->options));
|
$key = is_string($cache['key']) ? $cache['key'] : md5($field . serialize($this->options) . serialize($this->bind));
|
||||||
$result = Cache::get($key);
|
$result = Cache::get($key);
|
||||||
}
|
}
|
||||||
if (false === $result) {
|
if (false === $result) {
|
||||||
@@ -444,7 +444,7 @@ class Query
|
|||||||
if (empty($this->options['table'])) {
|
if (empty($this->options['table'])) {
|
||||||
$this->options['table'] = $this->getTable();
|
$this->options['table'] = $this->getTable();
|
||||||
}
|
}
|
||||||
$guid = is_string($cache['key']) ? $cache['key'] : md5($field . serialize($this->options));
|
$guid = is_string($cache['key']) ? $cache['key'] : md5($field . serialize($this->options) . serialize($this->bind));
|
||||||
$result = Cache::get($guid);
|
$result = Cache::get($guid);
|
||||||
}
|
}
|
||||||
if (false === $result) {
|
if (false === $result) {
|
||||||
@@ -596,7 +596,7 @@ class Query
|
|||||||
}
|
}
|
||||||
if ($lazyTime > 0) {
|
if ($lazyTime > 0) {
|
||||||
// 延迟写入
|
// 延迟写入
|
||||||
$guid = md5($this->getTable() . '_' . $field . '_' . serialize($condition));
|
$guid = md5($this->getTable() . '_' . $field . '_' . serialize($condition) . serialize($this->bind));
|
||||||
$step = $this->lazyWrite('inc', $guid, $step, $lazyTime);
|
$step = $this->lazyWrite('inc', $guid, $step, $lazyTime);
|
||||||
if (false === $step) {
|
if (false === $step) {
|
||||||
// 清空查询条件
|
// 清空查询条件
|
||||||
@@ -625,7 +625,7 @@ class Query
|
|||||||
}
|
}
|
||||||
if ($lazyTime > 0) {
|
if ($lazyTime > 0) {
|
||||||
// 延迟写入
|
// 延迟写入
|
||||||
$guid = md5($this->getTable() . '_' . $field . '_' . serialize($condition));
|
$guid = md5($this->getTable() . '_' . $field . '_' . serialize($condition) . serialize($this->bind));
|
||||||
$step = $this->lazyWrite('dec', $guid, $step, $lazyTime);
|
$step = $this->lazyWrite('dec', $guid, $step, $lazyTime);
|
||||||
if (false === $step) {
|
if (false === $step) {
|
||||||
// 清空查询条件
|
// 清空查询条件
|
||||||
@@ -2205,7 +2205,7 @@ class Query
|
|||||||
$options['where']['AND'] = $where;
|
$options['where']['AND'] = $where;
|
||||||
}
|
}
|
||||||
} elseif (!isset($key) && is_string($pk) && isset($options['where']['AND'][$pk])) {
|
} elseif (!isset($key) && is_string($pk) && isset($options['where']['AND'][$pk])) {
|
||||||
$key = $this->getCacheKey($options['where']['AND'][$pk], $options);
|
$key = $this->getCacheKey($options['where']['AND'][$pk], $options, $this->bind);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 生成UPDATE SQL语句
|
// 生成UPDATE SQL语句
|
||||||
@@ -2293,7 +2293,7 @@ class Query
|
|||||||
// 判断查询缓存
|
// 判断查询缓存
|
||||||
$cache = $options['cache'];
|
$cache = $options['cache'];
|
||||||
unset($options['cache']);
|
unset($options['cache']);
|
||||||
$key = is_string($cache['key']) ? $cache['key'] : md5(serialize($options));
|
$key = is_string($cache['key']) ? $cache['key'] : md5(serialize($options) . serialize($this->bind));
|
||||||
$resultSet = Cache::get($key);
|
$resultSet = Cache::get($key);
|
||||||
}
|
}
|
||||||
if (!$resultSet) {
|
if (!$resultSet) {
|
||||||
@@ -2385,8 +2385,9 @@ class Query
|
|||||||
* @access public
|
* @access public
|
||||||
* @param mixed $value 缓存数据
|
* @param mixed $value 缓存数据
|
||||||
* @param array $options 缓存参数
|
* @param array $options 缓存参数
|
||||||
|
* @param array $bind 绑定参数
|
||||||
*/
|
*/
|
||||||
protected function getCacheKey($value, $options)
|
protected function getCacheKey($value, $options, $bind = [])
|
||||||
{
|
{
|
||||||
if (is_scalar($value)) {
|
if (is_scalar($value)) {
|
||||||
$data = $value;
|
$data = $value;
|
||||||
@@ -2394,9 +2395,9 @@ class Query
|
|||||||
$data = $value[1];
|
$data = $value[1];
|
||||||
}
|
}
|
||||||
if (isset($data)) {
|
if (isset($data)) {
|
||||||
return 'think:' . $options['table'] . '|' . $data;
|
return 'think:' . (is_array($options['table']) ? key($options['table']) : $options['table']) . '|' . $data;
|
||||||
} else {
|
} else {
|
||||||
return md5(serialize($options));
|
return md5(serialize($options) . serialize($bind));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2424,7 +2425,7 @@ class Query
|
|||||||
// AR模式分析主键条件
|
// AR模式分析主键条件
|
||||||
$this->parsePkWhere($data, $options);
|
$this->parsePkWhere($data, $options);
|
||||||
} elseif (!empty($options['cache']) && true === $options['cache']['key'] && is_string($pk) && isset($options['where']['AND'][$pk])) {
|
} elseif (!empty($options['cache']) && true === $options['cache']['key'] && is_string($pk) && isset($options['where']['AND'][$pk])) {
|
||||||
$key = $this->getCacheKey($options['where']['AND'][$pk], $options);
|
$key = $this->getCacheKey($options['where']['AND'][$pk], $options, $this->bind);
|
||||||
}
|
}
|
||||||
|
|
||||||
$options['limit'] = 1;
|
$options['limit'] = 1;
|
||||||
@@ -2437,7 +2438,7 @@ class Query
|
|||||||
} elseif (is_string($cache['key'])) {
|
} elseif (is_string($cache['key'])) {
|
||||||
$key = $cache['key'];
|
$key = $cache['key'];
|
||||||
} elseif (!isset($key)) {
|
} elseif (!isset($key)) {
|
||||||
$key = md5(serialize($options));
|
$key = md5(serialize($options) . serialize($this->bind));
|
||||||
}
|
}
|
||||||
$result = Cache::get($key);
|
$result = Cache::get($key);
|
||||||
}
|
}
|
||||||
@@ -2648,7 +2649,7 @@ class Query
|
|||||||
// AR模式分析主键条件
|
// AR模式分析主键条件
|
||||||
$this->parsePkWhere($data, $options);
|
$this->parsePkWhere($data, $options);
|
||||||
} elseif (!isset($key) && is_string($pk) && isset($options['where']['AND'][$pk])) {
|
} elseif (!isset($key) && is_string($pk) && isset($options['where']['AND'][$pk])) {
|
||||||
$key = $this->getCacheKey($options['where']['AND'][$pk], $options);
|
$key = $this->getCacheKey($options['where']['AND'][$pk], $options, $this->bind);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (true !== $data && empty($options['where'])) {
|
if (true !== $data && empty($options['where'])) {
|
||||||
|
|||||||
Reference in New Issue
Block a user