добавлено кэширование класса Юзер

This commit is contained in:
rsgrinko committed 2022-04-18 17:41:14 +03:00
1 parent a4d65fa44d
commit 1412003d5e
2 files changed
+23 -9

No files matched your search

+10
View File
@@ -1,4 +1,10 @@
<?php
/**
* Версия сервиса
*/
define('VERSION', '1.0.0');
/**
* Путь до корня проекта
*/
@@ -34,3 +40,7 @@
*/
define('USER_ONLINE_TIME', 60 * 5);
/**
* Время жизни кэша
*/
define('CACHE_TTL', 3600);
+13 -9
View File
@@ -55,6 +55,7 @@
if (empty($id)) {
throw new CoreException('Передан некорректный идентификатор пользователя');
}
$this->id = $id;
}
@@ -65,8 +66,15 @@
*/
public function getAllUserData(): ?array
{
$result = (DB::getInstance())->getItem(self::TABLE, ['id' => $this->id]);
if ($result) {
$cacheId = md5('User_getAllUserData_' . $this->id);
if(Cache::check($cacheId)) {
$result = Cache::get($cacheId);
} else {
$result = (DB::getInstance())->getItem(self::TABLE, ['id' => $this->id]);
Cache::set($cacheId, $result);
}
if (!empty($result)) {
return $result;
} else {
return null;
@@ -360,14 +368,10 @@
*
* @return bool
*/
public static function isAdmin(): bool
public function isAdmin(): bool
{
if (self::isUser()) {
if (self::getFields(self::$id)['access_level'] == 'admin') {
return true;
} else {
return false;
}
if ($this->getAllUserData()['access_level'] == self::ACCESS_ADMIN) {
return true;
} else {
return false;
}