From 78deb5aecfe0437769b5db18b8d15ee331639210 Mon Sep 17 00:00:00 2001 From: rsgrinko Date: Tue, 21 Dec 2021 23:15:34 +0300 Subject: [PATCH] =?UTF-8?q?[*]=20=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=20=D0=BC?= =?UTF-8?q?=D0=B5=D0=BC=D0=BA=D1=8D=D1=88=D0=B0=20=D0=B8=20=D0=B4=D0=BE?= =?UTF-8?q?=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B0=20=D0=BA=D1=80=D0=B0?= =?UTF-8?q?=D0=B9=D0=BD=D1=8F=D1=8F=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inc/lib/CCache.class.php | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/inc/lib/CCache.class.php b/inc/lib/CCache.class.php index 46b2891..88cf731 100644 --- a/inc/lib/CCache.class.php +++ b/inc/lib/CCache.class.php @@ -70,8 +70,18 @@ class CCache */ public static function init($dir, $cache_ttl, $enabled = true):void { - self::$cache_dir = $dir; - self::$cache_ttl = $cache_ttl; + if(!isset($dir) or empty($dir)) { + self::$cache_dir = $dir; + } else { + self::$lastError = 'Incorrect cache path!'; + } + + if(!isset($cache_ttl) or empty($cache_ttl)) { + self::$cache_ttl = $cache_ttl; + } else { + self::$lastError = 'Incorrect cache TTL!'; + } + self::$cache_enabled = $enabled; } @@ -83,8 +93,8 @@ class CCache */ public function __callStatic($method, $args) { + self::$lastError = 'Unsupported method. Method: '.$method.', arguments: '.$args; echo json_encode(['status' => 'fail', 'error' => 'Unsupported method', 'method' => $method, 'args' => $args], JSON_UNESCAPED_UNICODE); - die(); } /** @@ -160,6 +170,7 @@ class CCache if (file_put_contents(self::$cache_dir . md5($name) . '.tmp', base64_encode(serialize($arValue)))) { return true; } else { + self::$lastError = 'Error writing cache "'.$name.'" to file: '.self::$cache_dir . md5($name) . '.tmp'; return false; } } @@ -180,6 +191,7 @@ class CCache self::$quantity++; self::$quantity_write++; if (!unlink(self::$cache_dir . $file)) { + self::$lastError = 'Error remove file: '.self::$cache_dir . $file; return false; } } @@ -199,6 +211,7 @@ class CCache if (!unlink(self::$cache_dir . md5($name) . '.tmp')) { self::$quantity++; self::$quantity_write++; + self::$lastError = 'Error remove file: '.self::$cache_dir . md5($name) . '.tmp'; return false; } } @@ -209,14 +222,14 @@ class CCache * Получение размера элемента кэша в байтах * * @param string $name Имя элемента кэша - * @return bool|int Размер элемента в байтах или false + * @return int Размер элемента в байтах или false */ - public static function getSize($name) + public static function getSize($name):int { // Получить размер элемента в кэше if (self::check($name)) { return filesize(self::$cache_dir . md5($name) . '.tmp'); } - return true; + return 0; } /**