实现请求缓存1天。
This commit is contained in:
38
vendor/topthink/think-orm/src/Model.php
vendored
38
vendor/topthink/think-orm/src/Model.php
vendored
@@ -121,6 +121,12 @@ abstract class Model implements JsonSerializable, ArrayAccess, Arrayable, Jsonab
|
||||
*/
|
||||
private $lazySave = false;
|
||||
|
||||
/**
|
||||
* 缓存自动更新标识
|
||||
* @var bool|string
|
||||
*/
|
||||
protected $cacheKey = false;
|
||||
|
||||
/**
|
||||
* Db对象
|
||||
* @var DbManager
|
||||
@@ -335,6 +341,18 @@ abstract class Model implements JsonSerializable, ArrayAccess, Arrayable, Jsonab
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置当前查询的自动缓存标识
|
||||
* @access public
|
||||
* @param string|bool $key 缓存标识
|
||||
* @return $this
|
||||
*/
|
||||
public function setCacheKey($key)
|
||||
{
|
||||
$this->cacheKey = $key;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前模型的数据表后缀
|
||||
* @access public
|
||||
@@ -641,7 +659,7 @@ abstract class Model implements JsonSerializable, ArrayAccess, Arrayable, Jsonab
|
||||
|
||||
$result = $db->where($where)
|
||||
->strict(false)
|
||||
->cache(true)
|
||||
->cache($this->cacheKey)
|
||||
->setOption('key', $this->key)
|
||||
->field($allowFields)
|
||||
->update($data);
|
||||
@@ -769,16 +787,20 @@ abstract class Model implements JsonSerializable, ArrayAccess, Arrayable, Jsonab
|
||||
|
||||
$pk = $this->getPk();
|
||||
|
||||
if (is_string($pk) && $replace) {
|
||||
$auto = true;
|
||||
}
|
||||
|
||||
$result = [];
|
||||
|
||||
$suffix = $this->getSuffix();
|
||||
|
||||
foreach ($dataSet as $key => $data) {
|
||||
if ($this->exists || (!empty($auto) && isset($data[$pk]))) {
|
||||
if ($replace) {
|
||||
$exists = true;
|
||||
foreach ((array) $pk as $field) {
|
||||
if (!isset($data[$field])) {
|
||||
$exists = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($replace && !empty($exists)) {
|
||||
$result[$key] = static::update($data, [], [], $suffix);
|
||||
} else {
|
||||
$result[$key] = static::create($data, $this->field, $this->replace, $suffix);
|
||||
@@ -809,7 +831,7 @@ abstract class Model implements JsonSerializable, ArrayAccess, Arrayable, Jsonab
|
||||
|
||||
$db->transaction(function () use ($where, $db) {
|
||||
// 删除当前模型数据
|
||||
$db->where($where)->delete();
|
||||
$db->where($where)->cache($this->cacheKey)->delete();
|
||||
|
||||
// 关联删除
|
||||
if (!empty($this->relationWrite)) {
|
||||
|
||||
Reference in New Issue
Block a user