mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-05 22:52:49 +08:00
改进Model类的get方法缓存判断
This commit is contained in:
@@ -619,7 +619,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
if ($cache) {
|
if ($cache) {
|
||||||
// 查找是否存在缓存
|
// 查找是否存在缓存
|
||||||
$name = basename(str_replace('\\', '/', get_called_class()));
|
$name = basename(str_replace('\\', '/', get_called_class()));
|
||||||
$guid = 'model_' . $name . '_' . $data;
|
$guid = md5('model_' . $name . '_' . serialize($data));
|
||||||
$result = Cache::get($guid);
|
$result = Cache::get($guid);
|
||||||
if ($result) {
|
if ($result) {
|
||||||
return new static($result);
|
return new static($result);
|
||||||
@@ -628,7 +628,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
|
|
||||||
$result = $db->find($data);
|
$result = $db->find($data);
|
||||||
|
|
||||||
if ($cache) {
|
if ($cache && $result instanceof Model) {
|
||||||
// 缓存模型数据
|
// 缓存模型数据
|
||||||
Cache::set($guid, $result->toArray());
|
Cache::set($guid, $result->toArray());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user