[*] переименованы методы класса CCache

This commit is contained in:
rsgrinko committed 2021-12-10 23:13:00 +03:00
1 parent 5625b8cfd2
commit eb18e5e6c9
7 files changed
+37 -37

No files matched your search

+3 -3
View File
@@ -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
View File
@@ -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){
+7 -7
View File
@@ -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'));
}