дикие правки

This commit is contained in:
rsgrinko committed 2022-04-18 20:03:46 +03:00
1 parent 1412003d5e
commit 9eacb906f2
543 files changed
+50249 -19

No files matched your search

+6 -1
View File
@@ -25,4 +25,9 @@
}
});
Cache::init(ROOT_PATH . '/core/cache/', true);
Cache::init(ROOT_PATH . '/core/cache/', true);
if(isset($_REQUEST['clear_cache']) && $_REQUEST['clear_cache'] === CODE_VALUE_Y) {
Cache::flush();
}
+5
View File
@@ -44,3 +44,8 @@
* Время жизни кэша
*/
define('CACHE_TTL', 3600);
/**
* Код значения Да
*/
define('CODE_VALUE_Y', 'Y');
+39 -5
View File
@@ -35,12 +35,12 @@
/**
* Инициализация кэша
*
* @param string $dir Директория хранения файлов кэша
* @param bool $enabled Флаг включения кэширования
* @param string $dir Директория хранения файлов кэша
* @param bool $enabled Флаг включения кэширования
*/
public static function init(string $dir, $enabled = true): void
{
self::$cacheDir = $dir;
self::$cacheDir = $dir;
self::$cacheEnabled = $enabled;
}
@@ -74,10 +74,28 @@
return self::$quantityWrite;
}
/**
* Получение информации о кэше
*
* @return array
*/
public static function getCacheInfo(): array
{
return [
'countAll' => self::$quantity,
'countWrite' => self::$quantityWrite,
'countRead' => self::$quantityRead,
'cacheDir' => self::$cacheDir,
'cachedCount' => self::getCachedCount(),
'size' => self::getCacheSize(),
];
}
/**
* Проверка наличия элемента в кэше
*
* @param string $name Имя элемента кэша
*
* @return bool Флаг наличия или отсутствия кэша
*/
public static function check(string $name): bool
@@ -95,6 +113,7 @@
* Получение кэшированных данных из кэша
*
* @param string $name Имя элемента кэша
*
* @return Кэшированные данные
*/
public static function get(string $name)
@@ -104,6 +123,16 @@
return unserialize(base64_decode(file_get_contents(self::$cacheDir . md5($name) . '.tmp')));
}
/**
* Получить количество кэшированных элементов
*
* @return int
*/
public static function getCachedCount()
{
return count(scandir(self::$cacheDir)) - 2;
}
/**
* Запись значения в кэш
*
@@ -134,7 +163,8 @@
public static function flush(): bool
{
foreach (scandir(self::$cacheDir) as $file) {
if ($file == '.' || $file == '..') continue;
if ($file == '.' || $file == '..')
continue;
self::$quantity++;
self::$quantityWrite++;
if (!unlink(self::$cacheDir . $file)) {
@@ -148,6 +178,7 @@
* Удаление элемента из кэша
*
* @param string $name Имя элемента кэша
*
* @return bool Флаг успеха
*/
public static function del(string $name): bool
@@ -166,6 +197,7 @@
* Получение размера элемента кэша в байтах
*
* @param string $name Имя элемента кэша
*
* @return int|null Размер элемента в байтах или null
*/
public static function getSize(string $name): ?int
@@ -185,7 +217,8 @@
{
$return_size = 0;
foreach (scandir(self::$cacheDir) as $file) {
if ($file == '.' or $file == '..') continue;
if ($file == '.' or $file == '..')
continue;
$return_size = $return_size + filesize(self::$cacheDir . $file);
}
return $return_size;
@@ -195,6 +228,7 @@
* Получение времени существованя кэша в секундах
*
* @param string $name Имя элемента кэша
*
* @return int Время в секундах или false
*/
public static function getAge(string $name): int
+4 -5
View File
@@ -67,7 +67,7 @@
public function getAllUserData(): ?array
{
$cacheId = md5('User_getAllUserData_' . $this->id);
if(Cache::check($cacheId)) {
if (Cache::check($cacheId)) {
$result = Cache::get($cacheId);
} else {
$result = (DB::getInstance())->getItem(self::TABLE, ['id' => $this->id]);
@@ -91,8 +91,8 @@
*/
public static function getUsers(string $limit = '10', $sort = 'ASC')
{
$cacheId = md5('User::getUsers(' . $limit . ', ' . $sort . ')');
if(Cache::check($cacheId)) {
$cacheId = md5('User_getUsers_' . $limit . '_' . $sort);
if (Cache::check($cacheId)) {
$res = Cache::get($cacheId);
} else {
$res = (DB::getInstance())->query('SELECT * FROM `' . self::TABLE . '` ORDER BY `id` ' . $sort . ' LIMIT ' . $limit);
@@ -296,7 +296,6 @@
{
$result = (DB::getInstance())->getItem(self::TABLE, ['login' => $login, 'password' => md5(self::$cryptoSalt . $password)], true);
if ($result) {
self::$id = $result['id'];
$_SESSION['id'] = $result['id'];
$_SESSION['authorize'] = 'Y';
$_SESSION['login'] = $result['login'];
@@ -321,7 +320,7 @@
*/
public static function getUserId(): ?int
{
if(self::isUser()) {
if (self::isUser()) {
return $_SESSION['id'];
} else {
return null;