* [misc] Select into for cache.

This commit is contained in:
朱金勇
2024-11-20 15:42:49 +08:00
parent aafac9c063
commit f1bb5c856f
2 changed files with 33 additions and 46 deletions
+27 -27
View File
@@ -626,22 +626,34 @@ class cache
$code = $this->getTableCode();
if(!$objectIdList)
{
$setCacheKey = $this->getSetCacheKey($code);
$objectIdList = $this->cache->get($setCacheKey);
if(!$objectIdList) return $this->initTableCache();
}
$keys = [];
foreach($objectIdList as $objectID) $keys[] = $this->getRawCacheKey($code, $objectID);
$objects = $this->cache->getMultiple($keys);
if(!$objects) return [];
$result = [];
$field = $this->getTableField();
foreach($objects as $object) $result[$object->$field] = $object;
/* Try get all objectIdList. */
$setCacheKey = $this->getSetCacheKey($code);
$allObjectIdList = $this->cache->get($setCacheKey);
/* No data in cache, init table cache. */
if(!$allObjectIdList)
{
$allData = $this->initTableCache();
if(empty($objectIdList)) return $allData;
foreach($allData as $objectId => $object)
{
if(in_array($objectId, $objectIdList)) $result[$objectId] = $object;
}
}
else
{
$keys = [];
foreach($objectIdList as $objectID) $keys[] = $this->getRawCacheKey($code, $objectID);
$objects = $this->cache->getMultiple($keys);
if(!$objects) return [];
$field = $this->getTableField();
foreach($objects as $object) $result[$object->$field] = $object;
}
return $result;
}
@@ -865,16 +877,4 @@ class cache
$this->reset();
}
/**
* 清空缓存。
* Clear cache.
*
* @access public
* @return void
*/
public function clear
{
$this->cache->clear();
}
}