mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-01 20:52:48 +08:00
改进Query类的自动缓存更新
This commit is contained in:
@@ -2187,8 +2187,8 @@ class Query
|
||||
} else {
|
||||
$options['where']['AND'] = $where;
|
||||
}
|
||||
} elseif (is_string($pk) && isset($options['where']['AND'][$pk]) && is_scalar($options['where']['AND'][$pk])) {
|
||||
$key = 'think:' . $options['table'] . '|' . $options['where']['AND'][$pk];
|
||||
} elseif (!isset($key) && is_string($pk) && isset($options['where']['AND'][$pk])) {
|
||||
$key = $this->getCacheKey($options['where']['AND'][$pk], $options);
|
||||
}
|
||||
// 生成UPDATE SQL语句
|
||||
$sql = $this->builder->update($data, $options);
|
||||
@@ -2339,6 +2339,18 @@ class Query
|
||||
return $resultSet;
|
||||
}
|
||||
|
||||
protected function getCacheKey($value, $options)
|
||||
{
|
||||
if (is_scalar($value)) {
|
||||
$data = $value;
|
||||
} elseif (is_array($value) && 'eq' == strtolower($value[0])) {
|
||||
$data = $value[1];
|
||||
}
|
||||
if (isset($data)) {
|
||||
return 'think:' . $options['table'] . '|' . $data;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查找单条记录
|
||||
* @access public
|
||||
@@ -2358,10 +2370,12 @@ class Query
|
||||
}
|
||||
// 分析查询表达式
|
||||
$options = $this->parseExpress();
|
||||
|
||||
$pk = $this->getPk($options);
|
||||
if (!is_null($data)) {
|
||||
// AR模式分析主键条件
|
||||
$this->parsePkWhere($data, $options);
|
||||
} elseif (!empty($options['cache']) && true === $options['cache']['key'] && is_string($pk) && isset($options['where']['AND'][$pk])) {
|
||||
$key = $this->getCacheKey($options['where']['AND'][$pk], $options);
|
||||
}
|
||||
|
||||
$options['limit'] = 1;
|
||||
@@ -2371,7 +2385,7 @@ class Query
|
||||
$cache = $options['cache'];
|
||||
if (true === $cache['key'] && !is_null($data) && !is_array($data)) {
|
||||
$key = 'think:' . (is_array($options['table']) ? key($options['table']) : $options['table']) . '|' . $data;
|
||||
} else {
|
||||
} elseif (!isset($key)) {
|
||||
$key = is_string($cache['key']) ? $cache['key'] : md5(serialize($options));
|
||||
}
|
||||
$result = Cache::get($key);
|
||||
@@ -2577,8 +2591,8 @@ class Query
|
||||
}
|
||||
// AR模式分析主键条件
|
||||
$this->parsePkWhere($data, $options);
|
||||
} elseif (is_string($pk) && isset($options['where']['AND'][$pk]) && is_scalar($options['where']['AND'][$pk])) {
|
||||
$key = 'think:' . $options['table'] . '|' . $options['where']['AND'][$pk];
|
||||
} elseif (!isset($key) && is_string($pk) && isset($options['where']['AND'][$pk])) {
|
||||
$key = $this->getCacheKey($options['where']['AND'][$pk], $options);
|
||||
}
|
||||
|
||||
if (true !== $data && empty($options['where'])) {
|
||||
|
||||
Reference in New Issue
Block a user