diff --git a/inc/func.php b/inc/func.php index 5a3cd43..495152a 100644 --- a/inc/func.php +++ b/inc/func.php @@ -189,8 +189,15 @@ function getClientInfo() { * @return array|bool */ function getUserDevices($userId) { - global $DB; - $res = $DB->query('SELECT * FROM devices WHERE user="'.$userId.'"'); + $cacheId = md5('getUserDevices_'.$userId); + if(CCache::checkCache($cacheId)){ + $res = CCache::getCache($cacheId); + } else { + global $DB; + $res = $DB->query('SELECT * FROM devices WHERE user="'.$userId.'"'); + CCache::writeCache($cacheId, $res); + } + if($res){ return $res; } else { diff --git a/inc/lib/CCache.class.php b/inc/lib/CCache.class.php index be79087..3f62b3c 100644 --- a/inc/lib/CCache.class.php +++ b/inc/lib/CCache.class.php @@ -86,17 +86,13 @@ class CCache * Получение кэшированых данных из кэша * * @param string $name Имя элемента кэша - * @return false|mixed Кэшированные данные + * @return mixed Кэшированные данные */ - public static function getCache($name) - { // Получить элемент из кэша + public static function getCache(string $name) + { self::$quantity++; self::$quantity_read++; - if (self::checkCache($name)) { - return unserialize(base64_decode(file_get_contents(self::$cache_dir . md5($name) . '.tmp'))); - } else { - return false; - } + return unserialize(base64_decode(file_get_contents(self::$cache_dir . md5($name) . '.tmp'))); } /**