hotfix CCache and enable use cache

This commit is contained in:
rsgrinko committed 2021-12-03 22:53:11 +03:00
1 parent fa02e60b5d
commit d5bdfbc33c
4 files changed
+116 -97

No files matched your search

+5
View File
@@ -32,6 +32,11 @@ define('USE_CACHE', true);
*/
define('CACHEDIR', $_SERVER['DOCUMENT_ROOT'].'/cache/');
/**
* Время актуальности кэша в секундах
*/
define('CACHE_TTL', 3600);
/**
* Сервер базы данных
*/
+10 -2
View File
@@ -69,8 +69,16 @@ function pre($arr, $stop = false) {
* @param int $userId
*/
function isHaveAccessToDevice($deviceId, $userId){
global $DB;
$arDevice = $DB->query('SELECT user FROM devices WHERE id="'.$deviceId.'"');
$cacheId = md5('isHaveAccessToDevice_'.$deviceId.'_'.$userId);
echo $cacheId;
if(CCache::checkCache($cacheId)){
$arDevice = CCache::getCache($cacheId);
} else {
global $DB;
$arDevice = $DB->query('SELECT user FROM devices WHERE id="'.$deviceId.'"');
CCache::writeCache($cacheId, $arDevice);
}
if($arDevice){
if($arDevice[0]['user'] == $userId){
+6 -7
View File
@@ -72,6 +72,9 @@ class CCache
if (!self::$cache_enabled) {
return false;
}
if(self::ageOfCache($name) > CACHE_TTL) {
return false;
}
if (file_exists(self::$cache_dir . md5($name) . '.tmp')) {
return true;
} else {
@@ -187,15 +190,11 @@ class CCache
* Получение времени существованя кэша в секундах
*
* @param string $name Имя элемента кэша
* @return false|int Время в секундах или false
* @return int Время в секундах или false
*/
public static function ageOfCache(string $name)
{ // Получить возраст элемента кэша
if (self::checkCache($name)) {
return (time() - filectime(self::$cache_dir . md5($name) . '.tmp'));
} else {
return false;
}
{
return (time() - filectime(self::$cache_dir . md5($name) . '.tmp'));
}
}