[*] переименованы методы класса CCache
This commit is contained in:
1 parent
5625b8cfd2
commit
eb18e5e6c9
7 files changed
+37
-37
No files matched your search
+6
-6
@@ -12,19 +12,19 @@
|
||||
require_once __DIR__ . '/inc/header.php';
|
||||
|
||||
$cacheId = md5('CIoT::getDevice_'.$deviceId);
|
||||
if(CCache::checkCache($cacheId)) {
|
||||
$arDevice = CCache::getCache($cacheId);
|
||||
if(CCache::check($cacheId)) {
|
||||
$arDevice = CCache::get($cacheId);
|
||||
} else {
|
||||
$arDevice = CIoT::getDevice($deviceId);
|
||||
CCache::writeCache($cacheId, $arDevice);
|
||||
CCache::write($cacheId, $arDevice);
|
||||
}
|
||||
|
||||
$cacheId = md5('CUser::getFields_'.$arDevice['user']);
|
||||
if(CCache::checkCache($cacheId)) {
|
||||
$arDeviceUser = CCache::getCache($cacheId);
|
||||
if(CCache::check($cacheId)) {
|
||||
$arDeviceUser = CCache::get($cacheId);
|
||||
} else {
|
||||
$arDeviceUser = CUser::getFields($arDevice['user']);
|
||||
CCache::writeCache($cacheId, $arDeviceUser);
|
||||
CCache::write($cacheId, $arDeviceUser);
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
+6
-6
@@ -36,11 +36,11 @@
|
||||
<tbody>
|
||||
<?php
|
||||
$cacheId = md5('CIoT::getCountDevices');
|
||||
if(CCache::checkCache($cacheId)) {
|
||||
$countDevices = CCache::getCache($cacheId);
|
||||
if(CCache::check($cacheId)) {
|
||||
$countDevices = CCache::get($cacheId);
|
||||
} else {
|
||||
$countDevices = CIoT::getCountDevices();
|
||||
CCache::writeCache($cacheId, $countDevices);
|
||||
CCache::write($cacheId, $countDevices);
|
||||
}
|
||||
|
||||
CPagination::execute($_REQUEST['page'], $countDevices, PAGINATION_LIMIT);
|
||||
@@ -48,11 +48,11 @@
|
||||
?>
|
||||
<?php
|
||||
$cacheId = md5('CIoT::getDevices_'.$limit.'_ASC');
|
||||
if(CCache::checkCache($cacheId)) {
|
||||
$arrDevices = CCache::getCache($cacheId);
|
||||
if(CCache::check($cacheId)) {
|
||||
$arrDevices = CCache::get($cacheId);
|
||||
} else {
|
||||
$arrDevices = CIoT::getDevices($limit, 'ASC');
|
||||
CCache::writeCache($cacheId, $arrDevices);
|
||||
CCache::write($cacheId, $arrDevices);
|
||||
}
|
||||
|
||||
foreach($arrDevices as $device):
|
||||
|
||||
+3
-3
@@ -22,11 +22,11 @@ if(isset($_REQUEST['save']) and $_REQUEST['save'] == 'Y'):
|
||||
endif;
|
||||
|
||||
|
||||
if (CCache::checkCache($cacheId)) {
|
||||
$arrUser = CCache::getCache($cacheId);
|
||||
if (CCache::check($cacheId)) {
|
||||
$arrUser = CCache::get($cacheId);
|
||||
} else {
|
||||
$arrUser = CUser::getFields($userId);
|
||||
CCache::writeCache($cacheId, $arrUser);
|
||||
CCache::write($cacheId, $arrUser);
|
||||
}
|
||||
//pre($arrUser);
|
||||
?>
|
||||
|
||||
+3
-3
@@ -40,12 +40,12 @@ CCron::init($DB); // инициализация крона
|
||||
|
||||
if(CUser::is_user()) {
|
||||
$cacheId = md5('CUser::getFields_'.CUser::$id);
|
||||
if(CCache::checkCache($cacheId)) {
|
||||
$USER = CCache::getCache($cacheId);
|
||||
if(CCache::check($cacheId)) {
|
||||
$USER = CCache::get($cacheId);
|
||||
} else {
|
||||
$USER = CUser::getFields();
|
||||
unset($USER['password']);
|
||||
CCache::writeCache($cacheId, $USER);
|
||||
CCache::write($cacheId, $USER);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
+6
-6
@@ -70,12 +70,12 @@ function pre($arr, $stop = false) {
|
||||
*/
|
||||
function isHaveAccessToDevice($deviceId, $userId){
|
||||
$cacheId = md5('isHaveAccessToDevice_'.$deviceId.'_'.$userId);
|
||||
if(CCache::checkCache($cacheId)){
|
||||
$arDevice = CCache::getCache($cacheId);
|
||||
if(CCache::check($cacheId)){
|
||||
$arDevice = CCache::get($cacheId);
|
||||
} else {
|
||||
global $DB;
|
||||
$arDevice = $DB->query('SELECT user FROM devices WHERE id="'.$deviceId.'"');
|
||||
CCache::writeCache($cacheId, $arDevice);
|
||||
CCache::write($cacheId, $arDevice);
|
||||
}
|
||||
|
||||
|
||||
@@ -189,12 +189,12 @@ function getClientInfo() {
|
||||
*/
|
||||
function getUserDevices($userId) {
|
||||
$cacheId = md5('getUserDevices_'.$userId);
|
||||
if(CCache::checkCache($cacheId)){
|
||||
$res = CCache::getCache($cacheId);
|
||||
if(CCache::check($cacheId)){
|
||||
$res = CCache::get($cacheId);
|
||||
} else {
|
||||
global $DB;
|
||||
$res = $DB->query('SELECT * FROM devices WHERE user="'.$userId.'"');
|
||||
CCache::writeCache($cacheId, $res);
|
||||
CCache::write($cacheId, $res);
|
||||
}
|
||||
|
||||
if($res){
|
||||
|
||||
@@ -67,12 +67,12 @@ class CCache
|
||||
* @param string $name Имя элемента кэша
|
||||
* @return bool Флаг наличия или отсутствия кэша
|
||||
*/
|
||||
public static function checkCache($name):bool
|
||||
public static function check($name):bool
|
||||
{ // Проверка наличия элемента в кэше
|
||||
if (!self::$cache_enabled) {
|
||||
return false;
|
||||
}
|
||||
if(self::ageOfCache($name) > CACHE_TTL) {
|
||||
if(self::getAge($name) > CACHE_TTL) {
|
||||
return false;
|
||||
}
|
||||
if (file_exists(self::$cache_dir . md5($name) . '.tmp')) {
|
||||
@@ -88,7 +88,7 @@ class CCache
|
||||
* @param string $name Имя элемента кэша
|
||||
* @return mixed Кэшированные данные
|
||||
*/
|
||||
public static function getCache(string $name)
|
||||
public static function get(string $name)
|
||||
{
|
||||
self::$quantity++;
|
||||
self::$quantity_read++;
|
||||
@@ -102,7 +102,7 @@ class CCache
|
||||
* @param mixed $arValue Значение элемента кэша
|
||||
* @return bool Флаг успешной или неудачной записи данных
|
||||
*/
|
||||
public static function writeCache($name, $arValue):bool
|
||||
public static function write($name, $arValue):bool
|
||||
{ // Записать элемент в кэш
|
||||
if (!self::$cache_enabled) {
|
||||
return false;
|
||||
@@ -142,7 +142,7 @@ class CCache
|
||||
*/
|
||||
public static function del($name):bool
|
||||
{ // Удалить элемент из кэша
|
||||
if (self::checkCache($name)) {
|
||||
if (self::check($name)) {
|
||||
if (!unlink(self::$cache_dir . md5($name) . '.tmp')) {
|
||||
self::$quantity++;
|
||||
self::$quantity_write++;
|
||||
@@ -160,7 +160,7 @@ class CCache
|
||||
*/
|
||||
public static function getSize($name)
|
||||
{ // Получить размер элемента в кэше
|
||||
if (self::checkCache($name)) {
|
||||
if (self::check($name)) {
|
||||
return filesize(self::$cache_dir . md5($name) . '.tmp');
|
||||
|
||||
}
|
||||
@@ -188,7 +188,7 @@ class CCache
|
||||
* @param string $name Имя элемента кэша
|
||||
* @return int Время в секундах или false
|
||||
*/
|
||||
public static function ageOfCache(string $name)
|
||||
public static function getAge(string $name)
|
||||
{
|
||||
return (time() - @filectime(self::$cache_dir . md5($name) . '.tmp'));
|
||||
}
|
||||
|
||||
@@ -3,11 +3,11 @@ require_once __DIR__ . '/inc/bootstrap.php';
|
||||
require_once __DIR__ . '/inc/header.php';
|
||||
|
||||
$cacheId = md5('CIoT::getDallasArrData_'.$USER['deviceId']);
|
||||
if(CCache::checkCache($cacheId)) {
|
||||
$arSensors = CCache::getCache($cacheId);
|
||||
if(CCache::check($cacheId)) {
|
||||
$arSensors = CCache::get($cacheId);
|
||||
} else {
|
||||
$arSensors = CIoT::getDallasArrData($USER['deviceId']);
|
||||
CCache::writeCache($cacheId, $arSensors);
|
||||
CCache::write($cacheId, $arSensors);
|
||||
}
|
||||
|
||||
|
||||
@@ -86,11 +86,11 @@ if(CCache::checkCache($cacheId)) {
|
||||
//pre($arSensors);
|
||||
foreach ($arSensors as $arSensor):
|
||||
$cacheId = md5('CIoT::getPlotDallasValues_'.$USER['deviceId'].'_'.$arSensor['sensor']);
|
||||
if(CCache::checkCache($cacheId) and CCache::ageOfCache($cacheId) < 300) {
|
||||
$arValues = CCache::getCache($cacheId);
|
||||
if(CCache::check($cacheId) and CCache::getAge($cacheId) < 300) {
|
||||
$arValues = CCache::get($cacheId);
|
||||
} else {
|
||||
$arValues = CIoT::getPlotDallasValues($USER['deviceId'], $arSensor['sensor']);
|
||||
CCache::writeCache($cacheId, $arValues);
|
||||
CCache::write($cacheId, $arValues);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user