From a0ce19a311300f4448594a99e2dcf9aa6cd5afeb Mon Sep 17 00:00:00 2001 From: rsgrinko Date: Tue, 21 Dec 2021 22:48:34 +0300 Subject: [PATCH] =?UTF-8?q?[+]=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D0=BF=D0=BE=D0=B4=D0=B4=D0=B5=D1=80=D0=B6?= =?UTF-8?q?=D0=BA=D0=B0=20=D0=B0=D0=BD=D0=B0=D0=BB=D0=BE=D0=B3=D0=BE=D0=B3?= =?UTF-8?q?=D0=BE=20=D0=BF=D0=BE=D1=80=D1=82=D0=B0=20A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ajax/getDallasData.php | 9 ++++++++- inc/lib/CIoT.class.php | 6 +++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/ajax/getDallasData.php b/ajax/getDallasData.php index 412eaa8..0125985 100644 --- a/ajax/getDallasData.php +++ b/ajax/getDallasData.php @@ -20,7 +20,14 @@ die('403 - Access denied'); } - $arDallasData = CIoT::getDallasData($deviceId, $sensor); + $cacheId = md5('CIoT::getSensorData_'.$deviceId.'_'.$sensor); + if(CCache::check($cacheId) and CCache::getAge($cacheId) < 10) { + $arDallasData = CCache::get($cacheId); + } else { + $arDallasData = CIoT::getSensorData($deviceId, $sensor); + CCache::write($cacheId, $arDallasData); + } + $result = array('sensor' => $arDallasData['sensor'], 'value' => $arDallasData['value']); diff --git a/inc/lib/CIoT.class.php b/inc/lib/CIoT.class.php index 008efa5..d937caa 100644 --- a/inc/lib/CIoT.class.php +++ b/inc/lib/CIoT.class.php @@ -158,11 +158,11 @@ class CIoT { * Получение последнюю актуальную температуру датчика DS18B20 из базы * * @param $deviceId - * @param $ds + * @param $sensor * @return mixed */ - public static function getDallasData($deviceId, $ds){ - $result = self::$DB->query('SELECT * FROM sensors WHERE device="'.$deviceId.'" and sensor="'.$ds.'" ORDER BY id DESC LIMIT 1'); + public static function getSensorData($deviceId, $sensor){ + $result = self::$DB->query('SELECT * FROM sensors WHERE device="'.$deviceId.'" and sensor="'.$sensor.'" ORDER BY id DESC LIMIT 1'); return $result[0]; }