改进Model类的get方法缓存判断

This commit is contained in:
thinkphp
2016-04-10 16:40:48 +08:00
parent e39b72c21c
commit dab21914d8

View File

@@ -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());
} }