Rework frontend
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\App\Cache;
|
||||
|
||||
use App\Enums\CacheKeys;
|
||||
use App\Models\AcademicJournal;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class AcademicJournalCacheService extends AbstractCacheService implements CacheInterface
|
||||
{
|
||||
private const DEFAULT_TTL = 3600;
|
||||
|
||||
public function clearCache($entity): void
|
||||
{
|
||||
if ($entity instanceof AcademicJournal) {
|
||||
$this->clearAllCacheByModel();
|
||||
}
|
||||
}
|
||||
|
||||
public function clearAllCacheByModel(): void
|
||||
{
|
||||
$this->clearCacheByPrefix(CacheKeys::ACADEMIC_JOURNAL_PREFIX->value.'*');
|
||||
$this->clearCacheByPrefix(CacheKeys::ACADEMIC_JOURNALS_PREFIX->value.'*');
|
||||
}
|
||||
|
||||
public function getCachedData(string $key)
|
||||
{
|
||||
return Cache::get($key);
|
||||
}
|
||||
|
||||
public function cacheData(string $key, $data, int $ttl = null): void
|
||||
{
|
||||
Cache::put($key, $data, $ttl ?? self::DEFAULT_TTL);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\App\Cache;
|
||||
|
||||
use App\Enums\CacheKeys;
|
||||
use App\Models\AdditionalEducation;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class AdditionalEducationCacheService extends AbstractCacheService implements CacheInterface
|
||||
{
|
||||
private const DEFAULT_TTL = 3600;
|
||||
|
||||
public function clearCache($entity): void
|
||||
{
|
||||
if ($entity instanceof AdditionalEducation) {
|
||||
$this->clearAllCacheByModel();
|
||||
}
|
||||
}
|
||||
|
||||
public function clearAllCacheByModel(): void
|
||||
{
|
||||
$this->clearCacheByPrefix(CacheKeys::ADDITIONAL_EDUCATIONAL_PROGRAM_PREFIX->value.'*');
|
||||
$this->clearCacheByPrefix(CacheKeys::ADDITIONAL_EDUCATIONAL_PROGRAMS_PREFIX->value.'*');
|
||||
}
|
||||
|
||||
public function getCachedData(string $key)
|
||||
{
|
||||
return Cache::get($key);
|
||||
}
|
||||
|
||||
public function cacheData(string $key, $data, int $ttl = null): void
|
||||
{
|
||||
Cache::put($key, $data, $ttl ?? self::DEFAULT_TTL);
|
||||
}
|
||||
}
|
||||
@@ -2,48 +2,30 @@
|
||||
|
||||
namespace App\Services\App\Cache;
|
||||
|
||||
use App\Enums\CacheKeys;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class CategoryCacheService extends AbstractCacheService implements CacheInterface
|
||||
{
|
||||
/**
|
||||
* Очищает кеш, связанный с постом.
|
||||
*
|
||||
* @param mixed $entity Пост или связанная сущность
|
||||
* @return void
|
||||
*/
|
||||
private const DEFAULT_TTL = 3600;
|
||||
|
||||
public function clearCache($entity): void
|
||||
{
|
||||
$this->clearAllCacheByModel();
|
||||
}
|
||||
|
||||
public function clearAllCacheByModel(): void
|
||||
{
|
||||
$this->clearCacheByPrefix('categories*');
|
||||
$this->clearCacheByPrefix('category_content_*');
|
||||
$this->clearCacheByPrefix(CacheKeys::CATEGORIES_PREFIX->value.'*');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Получает кешированные данные по ключу.
|
||||
*
|
||||
* @param string $key Ключ кеша
|
||||
* @return mixed
|
||||
*/
|
||||
public function getCachedData(string $key)
|
||||
{
|
||||
return Cache::get($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Кеширует данные по ключу.
|
||||
*
|
||||
* @param string $key Ключ кеша
|
||||
* @param mixed $data Данные для кеширования
|
||||
* @param int $ttl Время жизни кеша в секундах
|
||||
* @return void
|
||||
*/
|
||||
public function cacheData(string $key, $data, int $ttl = 3600): void
|
||||
public function cacheData(string $key, $data, int $ttl = null): void
|
||||
{
|
||||
Cache::put($key, $data, $ttl);
|
||||
Cache::put($key, $data, $ttl ?? self::DEFAULT_TTL);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\App\Cache;
|
||||
|
||||
use App\Enums\CacheKeys;
|
||||
use App\Models\ContactWidget;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class ContactWidgetCacheService extends AbstractCacheService implements CacheInterface
|
||||
{
|
||||
private const DEFAULT_TTL = 3600;
|
||||
|
||||
public function clearCache($entity): void
|
||||
{
|
||||
if ($entity instanceof ContactWidget) {
|
||||
$this->clearAllCacheByModel();
|
||||
}
|
||||
}
|
||||
|
||||
public function clearAllCacheByModel(): void
|
||||
{
|
||||
$this->clearCacheByPrefix(CacheKeys::CONTACT_WIDGET_PREFIX->value.'*');
|
||||
$this->clearCacheByPrefix(CacheKeys::CONTACT_WIDGETS_PREFIX->value.'*');
|
||||
}
|
||||
|
||||
public function getCachedData(string $key)
|
||||
{
|
||||
return Cache::get($key);
|
||||
}
|
||||
|
||||
public function cacheData(string $key, $data, int $ttl = null): void
|
||||
{
|
||||
Cache::put($key, $data, $ttl ?? self::DEFAULT_TTL);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\App\Cache;
|
||||
|
||||
use App\Enums\CacheKeys;
|
||||
use App\Models\Department;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class DepartmentCacheService extends AbstractCacheService implements CacheInterface
|
||||
{
|
||||
private const DEFAULT_TTL = 3600;
|
||||
|
||||
public function clearCache($entity): void
|
||||
{
|
||||
if ($entity instanceof Department) {
|
||||
$this->clearAllCacheByModel();
|
||||
}
|
||||
}
|
||||
|
||||
public function clearAllCacheByModel(): void
|
||||
{
|
||||
$this->clearCacheByPrefix(CacheKeys::DEPARTMENT_PREFIX->value.'*');
|
||||
$this->clearCacheByPrefix(CacheKeys::DEPARTMENTS_PREFIX->value.'*');
|
||||
}
|
||||
|
||||
public function getCachedData(string $key)
|
||||
{
|
||||
return Cache::get($key);
|
||||
}
|
||||
|
||||
public function cacheData(string $key, $data, int $ttl = null): void
|
||||
{
|
||||
Cache::put($key, $data, $ttl ?? self::DEFAULT_TTL);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\App\Cache;
|
||||
|
||||
use App\Models\Division;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class DivisionCacheService extends AbstractCacheService implements CacheInterface
|
||||
{
|
||||
private const CACHE_PREFIX = 'division_';
|
||||
private const ALL_CACHE_KEY = 'division_all';
|
||||
private const DEFAULT_TTL = 3600;
|
||||
|
||||
public function clearCache($entity): void
|
||||
{
|
||||
if ($entity instanceof Division) {
|
||||
$this->clearAllCacheByModel();
|
||||
}
|
||||
}
|
||||
|
||||
public function clearAllCacheByModel(): void
|
||||
{
|
||||
$this->clearCacheByPrefix(self::CACHE_PREFIX.'*');
|
||||
$this->clearAllDivisionsCache();
|
||||
}
|
||||
|
||||
public function getCachedData(string $key)
|
||||
{
|
||||
return Cache::get($key);
|
||||
}
|
||||
|
||||
public function cacheData(string $key, $data, int $ttl = null): void
|
||||
{
|
||||
Cache::put($key, $data, $ttl ?? self::DEFAULT_TTL);
|
||||
}
|
||||
|
||||
public function getCacheKey(int $id): string
|
||||
{
|
||||
return self::CACHE_PREFIX . $id;
|
||||
}
|
||||
|
||||
public function getAllCacheKey(): string
|
||||
{
|
||||
return self::ALL_CACHE_KEY;
|
||||
}
|
||||
|
||||
private function forgetDivisionCache(int $id): void
|
||||
{
|
||||
Cache::forget($this->getCacheKey($id));
|
||||
}
|
||||
|
||||
private function clearAllDivisionsCache(): void
|
||||
{
|
||||
Cache::forget(self::ALL_CACHE_KEY);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\App\Cache;
|
||||
|
||||
use App\Enums\CacheKeys;
|
||||
use App\Models\EducationalProgram;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class EducationalProgramCacheService extends AbstractCacheService implements CacheInterface
|
||||
{
|
||||
private const DEFAULT_TTL = 3600;
|
||||
|
||||
public function clearCache($entity): void
|
||||
{
|
||||
if ($entity instanceof EducationalProgram) {
|
||||
$this->clearAllCacheByModel();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function clearAllCacheByModel(): void
|
||||
{
|
||||
$this->clearCacheByPrefix(CacheKeys::EDUCATION_PROGRAMS_PREFIX->value.'*');
|
||||
$this->clearCacheByPrefix(CacheKeys::EDUCATION_PROGRAM_PREFIX->value.'*');
|
||||
|
||||
}
|
||||
|
||||
public function getCachedData(string $key)
|
||||
{
|
||||
return Cache::get($key);
|
||||
}
|
||||
|
||||
public function cacheData(string $key, $data, int $ttl = null): void
|
||||
{
|
||||
Cache::put($key, $data, $ttl ?? self::DEFAULT_TTL);
|
||||
}
|
||||
|
||||
public function getCacheKey(int $id): string
|
||||
{
|
||||
return CacheKeys::EDUCATION_PROGRAM_PREFIX->value . $id;
|
||||
}
|
||||
|
||||
private function forgetProgramCache(int $id): void
|
||||
{
|
||||
Cache::forget($this->getCacheKey($id));
|
||||
}
|
||||
|
||||
private function clearAllProgramsCache(): void
|
||||
{
|
||||
Cache::forget(CacheKeys::EDUCATION_PROGRAMS_PREFIX->value . '*');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\App\Cache;
|
||||
|
||||
use App\Enums\CacheKeys;
|
||||
use App\Models\Event;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class EventCacheService extends AbstractCacheService implements CacheInterface
|
||||
{
|
||||
private const DEFAULT_TTL = 3600;
|
||||
|
||||
public function clearCache($entity): void
|
||||
{
|
||||
if ($entity instanceof Event) {
|
||||
$this->clearAllCacheByModel();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function clearAllCacheByModel(): void
|
||||
{
|
||||
$this->clearCacheByPrefix(CacheKeys::EVENT_PREFIX->value.'*');
|
||||
$this->clearAllEventsCache();
|
||||
}
|
||||
|
||||
public function getCachedData(string $key)
|
||||
{
|
||||
return Cache::get($key);
|
||||
}
|
||||
|
||||
public function cacheData(string $key, $data, int $ttl = null): void
|
||||
{
|
||||
Cache::put($key, $data, $ttl ?? self::DEFAULT_TTL);
|
||||
}
|
||||
|
||||
|
||||
private function clearAllEventsCache(): void
|
||||
{
|
||||
Cache::forget(CacheKeys::EVENTS_PREFIX->value.'*');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\App\Cache;
|
||||
|
||||
use App\Enums\CacheKeys;
|
||||
use App\Models\Faculty;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class FacultyCacheService extends AbstractCacheService implements CacheInterface
|
||||
{
|
||||
private const DEFAULT_TTL = 3600;
|
||||
|
||||
public function clearCache($entity): void
|
||||
{
|
||||
if ($entity instanceof Faculty) {
|
||||
$this->clearAllCacheByModel();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function clearAllCacheByModel(): void
|
||||
{
|
||||
$this->clearCacheByPrefix(CacheKeys::FACULTY_PREFIX->value.'*');
|
||||
$this->clearAllFacultiesCache();
|
||||
}
|
||||
|
||||
public function getCachedData(string $key)
|
||||
{
|
||||
return Cache::get($key);
|
||||
}
|
||||
|
||||
public function cacheData(string $key, $data, int $ttl = null): void
|
||||
{
|
||||
Cache::put($key, $data, $ttl ?? self::DEFAULT_TTL);
|
||||
}
|
||||
|
||||
|
||||
private function clearAllFacultiesCache(): void
|
||||
{
|
||||
Cache::forget(CacheKeys::FACULTIES_PREFIX->value.'*');
|
||||
}
|
||||
}
|
||||
@@ -2,43 +2,36 @@
|
||||
|
||||
namespace App\Services\App\Cache;
|
||||
|
||||
use App\Enums\CacheKeys;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class MainSectionCacheService extends AbstractCacheService implements CacheInterface
|
||||
{
|
||||
/**
|
||||
* Очищает кеш, связанный с постом.
|
||||
*
|
||||
* @param mixed $entity Пост или связанная сущность
|
||||
* @return void
|
||||
*/
|
||||
private const DEFAULT_TTL = 3600;
|
||||
|
||||
public function clearCache($entity): void
|
||||
{
|
||||
$this->clearCacheByPrefix('posts_');
|
||||
$this->clearNavigationCache();
|
||||
}
|
||||
|
||||
public function clearAllCacheByModel(): void
|
||||
{
|
||||
$this->clearNavigationCache();
|
||||
}
|
||||
|
||||
/**
|
||||
* Получает кешированные данные по ключу.
|
||||
*
|
||||
* @param string $key Ключ кеша
|
||||
* @return mixed
|
||||
*/
|
||||
public function getCachedData(string $key)
|
||||
{
|
||||
return Cache::get($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Кеширует данные по ключу.
|
||||
*
|
||||
* @param string $key Ключ кеша
|
||||
* @param mixed $data Данные для кеширования
|
||||
* @param int $ttl Время жизни кеша в секундах
|
||||
* @return void
|
||||
*/
|
||||
public function cacheData(string $key, $data, int $ttl = 3600): void
|
||||
public function cacheData(string $key, $data, int $ttl = null): void
|
||||
{
|
||||
Cache::put($key, $data, $ttl);
|
||||
Cache::put($key, $data, $ttl ?? self::DEFAULT_TTL);
|
||||
}
|
||||
|
||||
|
||||
private function clearNavigationCache(): void
|
||||
{
|
||||
Cache::forget(CacheKeys::NAVIGATION_PREFIX->value);
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\App\Cache;
|
||||
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class MainSliderCacheService extends AbstractCacheService implements CacheInterface
|
||||
{
|
||||
/**
|
||||
* Очищает кеш, связанный с постом.
|
||||
*
|
||||
* @param mixed $entity Пост или связанная сущность
|
||||
* @return void
|
||||
*/
|
||||
public function clearCache($entity): void
|
||||
{
|
||||
}
|
||||
|
||||
public function clearAllCacheByModel(): void
|
||||
{
|
||||
$this->clearCacheByPrefix('active_sliders*');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Получает кешированные данные по ключу.
|
||||
*
|
||||
* @param string $key Ключ кеша
|
||||
* @return mixed
|
||||
*/
|
||||
public function getCachedData(string $key)
|
||||
{
|
||||
return Cache::get($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Кеширует данные по ключу.
|
||||
*
|
||||
* @param string $key Ключ кеша
|
||||
* @param mixed $data Данные для кеширования
|
||||
* @param int $ttl Время жизни кеша в секундах
|
||||
* @return void
|
||||
*/
|
||||
public function cacheData(string $key, $data, int $ttl = 3600): void
|
||||
{
|
||||
Cache::put($key, $data, $ttl);
|
||||
}
|
||||
}
|
||||
@@ -2,62 +2,42 @@
|
||||
|
||||
namespace App\Services\App\Cache;
|
||||
|
||||
use App\Enums\CacheKeys;
|
||||
use App\Models\Page;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Redis;
|
||||
|
||||
class PageCacheService extends AbstractCacheService implements CacheInterface
|
||||
{
|
||||
/**
|
||||
* Очищает кеш, связанный с постом.
|
||||
*
|
||||
* @param mixed $entity Пост или связанная сущность
|
||||
* @return void
|
||||
*/
|
||||
private const DEFAULT_TTL = 3600;
|
||||
|
||||
public function clearCache($entity): void
|
||||
{
|
||||
$cacheKeyByPath = md5($entity->path);
|
||||
$cacheKeyById = md5($entity->id);
|
||||
|
||||
|
||||
|
||||
Cache::forget('page_' . $cacheKeyByPath);
|
||||
Cache::forget('page_' . $cacheKeyById);
|
||||
|
||||
Cache::forget('navigation');
|
||||
|
||||
if ($entity instanceof Page) {
|
||||
$this->clearAllCacheByModel();
|
||||
$this->clearNavigationCache();
|
||||
}
|
||||
}
|
||||
|
||||
public function clearAllCacheByModel(): void
|
||||
{
|
||||
$this->clearCacheByPrefix('page_*');
|
||||
$this->clearCacheByPrefix('page_data_*');
|
||||
Cache::forget('navigation');
|
||||
|
||||
$this->clearCacheByPrefix(CacheKeys::PAGE_PREFIX->value.'*');
|
||||
$this->clearCacheByPrefix(CacheKeys::PAGE_DATA_PREFIX->value.'*');
|
||||
$this->clearNavigationCache();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Получает кешированные данные по ключу.
|
||||
*
|
||||
* @param string $key Ключ кеша
|
||||
* @return mixed
|
||||
*/
|
||||
public function getCachedData(string $key)
|
||||
{
|
||||
return Cache::get($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Кеширует данные по ключу.
|
||||
*
|
||||
* @param string $key Ключ кеша
|
||||
* @param mixed $data Данные для кеширования
|
||||
* @param int $ttl Время жизни кеша в секундах
|
||||
* @return void
|
||||
*/
|
||||
public function cacheData(string $key, $data, int $ttl = 3600): void
|
||||
public function cacheData(string $key, $data, int $ttl = null): void
|
||||
{
|
||||
Cache::put($key, $data, $ttl);
|
||||
Cache::put($key, $data, $ttl ?? self::DEFAULT_TTL);
|
||||
}
|
||||
|
||||
|
||||
private function clearNavigationCache(): void
|
||||
{
|
||||
Cache::forget(CacheKeys::NAVIGATION_PREFIX->value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\App\Cache;
|
||||
|
||||
use App\Enums\CacheKeys;
|
||||
use App\Models\PageReferenceList;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class PageReferenceListCacheService extends AbstractCacheService implements CacheInterface
|
||||
{
|
||||
private const DEFAULT_TTL = 3600;
|
||||
|
||||
public function clearCache($entity): void
|
||||
{
|
||||
if ($entity instanceof PageReferenceList) {
|
||||
$this->clearAllCacheByModel();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function clearAllCacheByModel(): void
|
||||
{
|
||||
$this->clearCacheByPrefix(CacheKeys::PAGE_REFERENCE_LIST_PREFIX->value.'*');
|
||||
$this->clearAllReferencesCache();
|
||||
}
|
||||
|
||||
public function getCachedData(string $key)
|
||||
{
|
||||
return Cache::get($key);
|
||||
}
|
||||
|
||||
public function cacheData(string $key, $data, int $ttl = null): void
|
||||
{
|
||||
Cache::put($key, $data, $ttl ?? self::DEFAULT_TTL);
|
||||
}
|
||||
|
||||
|
||||
private function clearAllReferencesCache(): void
|
||||
{
|
||||
Cache::forget(CacheKeys::PAGE_REFERENCE_LISTS_PREFIX->value.'*');
|
||||
}
|
||||
}
|
||||
@@ -2,59 +2,56 @@
|
||||
|
||||
namespace App\Services\App\Cache;
|
||||
|
||||
use App\Enums\CacheKeys;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Redis;
|
||||
|
||||
class PostCacheService extends AbstractCacheService implements CacheInterface
|
||||
{
|
||||
private const DEFAULT_TTL = 3600;
|
||||
|
||||
/**
|
||||
* Очищает кеш, связанный с постом.
|
||||
*
|
||||
* @param mixed $entity Пост или связанная сущность
|
||||
* @return void
|
||||
* Clear cache for specific post
|
||||
*/
|
||||
public function clearCache($entity): void
|
||||
{
|
||||
$cacheKeyBySlug = md5($entity->slug);
|
||||
$cacheKeyById = md5($entity->id);
|
||||
|
||||
Cache::forget('post_' .$cacheKeyBySlug);
|
||||
Cache::forget('post_' .$cacheKeyById);
|
||||
|
||||
$this->clearCacheByPrefix('recent_posts*');
|
||||
|
||||
}
|
||||
|
||||
public function clearAllCacheByModel(): void
|
||||
{
|
||||
$this->clearCacheByPrefix('post_*');
|
||||
$this->clearCacheByPrefix('posts_*');
|
||||
$this->clearCacheByPrefix('recent_posts*');
|
||||
$this->forgetPostCache($entity->slug, $entity->id);
|
||||
$this->clearRecentPostsCache();
|
||||
}
|
||||
|
||||
/**
|
||||
* Получает кешированные данные по ключу.
|
||||
*
|
||||
* @param string $key Ключ кеша
|
||||
* @return mixed
|
||||
* Clear all cache related to posts
|
||||
*/
|
||||
public function clearAllCacheByModel(): void
|
||||
{
|
||||
$this->clearCacheByPrefix(CacheKeys::POST_PREFIX->value.'*');
|
||||
$this->clearCacheByPrefix(CacheKeys::POSTS_PREFIX->value.'*');
|
||||
$this->clearRecentPostsCache();
|
||||
}
|
||||
|
||||
public function getCachedData(string $key)
|
||||
{
|
||||
return Cache::get($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Кеширует данные по ключу.
|
||||
*
|
||||
* @param string $key Ключ кеша
|
||||
* @param mixed $data Данные для кеширования
|
||||
* @param int $ttl Время жизни кеша в секундах
|
||||
* @return void
|
||||
*/
|
||||
public function cacheData(string $key, $data, int $ttl = 3600): void
|
||||
public function cacheData(string $key, $data, int $ttl = null): void
|
||||
{
|
||||
Cache::put($key, $data, $ttl);
|
||||
Cache::put($key, $data, $ttl ?? self::DEFAULT_TTL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Forget cache for specific post by slug and id
|
||||
*/
|
||||
private function forgetPostCache(string $slug, int $id): void
|
||||
{
|
||||
Cache::forget(CacheKeys::POST_PREFIX->value.md5($slug));
|
||||
Cache::forget(CacheKeys::POST_PREFIX->value.md5($id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear recent posts cache
|
||||
*/
|
||||
private function clearRecentPostsCache(): void
|
||||
{
|
||||
$this->clearCacheByPrefix(CacheKeys::RECENT_POSTS_PREFIX->value.'*');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\App\Cache;
|
||||
|
||||
use App\Enums\CacheKeys;
|
||||
use App\Models\Schedule;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class ScheduleCacheService extends AbstractCacheService implements CacheInterface
|
||||
{
|
||||
private const DEFAULT_TTL = 3600;
|
||||
|
||||
public function clearCache($entity): void
|
||||
{
|
||||
if ($entity instanceof Schedule) {
|
||||
$this->clearAllCacheByModel();
|
||||
}
|
||||
}
|
||||
|
||||
public function clearAllCacheByModel(): void
|
||||
{
|
||||
$this->clearCacheByPrefix(CacheKeys::SCHEDULE_PREFIX->value.'*');
|
||||
$this->clearAllSchedulesCache();
|
||||
}
|
||||
|
||||
public function getCachedData(string $key)
|
||||
{
|
||||
return Cache::get($key);
|
||||
}
|
||||
|
||||
public function cacheData(string $key, $data, int $ttl = null): void
|
||||
{
|
||||
Cache::put($key, $data, $ttl ?? self::DEFAULT_TTL);
|
||||
}
|
||||
|
||||
|
||||
private function forgetScheduleCache(int $id): void
|
||||
{
|
||||
Cache::forget($this->getCacheKey($id));
|
||||
}
|
||||
|
||||
private function clearAllSchedulesCache(): void
|
||||
{
|
||||
Cache::forget(CacheKeys::SCHEDULES_PREFIX->value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\App\Cache;
|
||||
|
||||
use App\Enums\CacheKeys;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class SliderCacheService extends AbstractCacheService implements CacheInterface
|
||||
{
|
||||
private const DEFAULT_TTL = 3600;
|
||||
|
||||
public function clearCache($entity): void
|
||||
{
|
||||
$this->clearAllCacheByModel();
|
||||
}
|
||||
|
||||
public function clearAllCacheByModel(): void
|
||||
{
|
||||
$this->clearSliderCache();
|
||||
}
|
||||
|
||||
public function getCachedData(string $key)
|
||||
{
|
||||
return Cache::get($key);
|
||||
}
|
||||
|
||||
public function cacheData(string $key, $data, int $ttl = null): void
|
||||
{
|
||||
Cache::put($key, $data, $ttl ?? self::DEFAULT_TTL);
|
||||
}
|
||||
|
||||
private function clearSliderCache(): void
|
||||
{
|
||||
$this->clearCacheByPrefix(CacheKeys::SLIDER_PREFIX->value.'*');
|
||||
}
|
||||
}
|
||||
@@ -2,42 +2,38 @@
|
||||
|
||||
namespace App\Services\App\Cache;
|
||||
|
||||
use App\Enums\CacheKeys;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class SubSectionCacheService extends AbstractCacheService implements CacheInterface
|
||||
{
|
||||
/**
|
||||
* Очищает кеш, связанный с постом.
|
||||
*
|
||||
* @param mixed $entity Пост или связанная сущность
|
||||
* @return void
|
||||
*/
|
||||
private const DEFAULT_TTL = 3600;
|
||||
|
||||
public function clearCache($entity): void
|
||||
{
|
||||
$this->clearCacheByPrefix('posts_');
|
||||
$this->clearAllCacheByModel();
|
||||
}
|
||||
|
||||
public function clearAllCacheByModel(): void
|
||||
{
|
||||
$this->clearNavigationCache();
|
||||
}
|
||||
|
||||
/**
|
||||
* Получает кешированные данные по ключу.
|
||||
*
|
||||
* @param string $key Ключ кеша
|
||||
* @return mixed
|
||||
*/
|
||||
public function getCachedData(string $key)
|
||||
{
|
||||
return Cache::get($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Кеширует данные по ключу.
|
||||
*
|
||||
* @param string $key Ключ кеша
|
||||
* @param mixed $data Данные для кеширования
|
||||
* @param int $ttl Время жизни кеша в секундах
|
||||
* @return void
|
||||
*/
|
||||
public function cacheData(string $key, $data, int $ttl = 3600): void
|
||||
public function cacheData(string $key, $data, int $ttl = null): void
|
||||
{
|
||||
Cache::put($key, $data, $ttl);
|
||||
Cache::put($key, $data, $ttl ?? self::DEFAULT_TTL);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private function clearNavigationCache(): void
|
||||
{
|
||||
Cache::forget(CacheKeys::NAVIGATION_PREFIX->value);
|
||||
}
|
||||
}
|
||||
@@ -2,49 +2,47 @@
|
||||
|
||||
namespace App\Services\App\Cache;
|
||||
|
||||
use App\Enums\CacheKeys;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class TagCacheService extends AbstractCacheService implements CacheInterface
|
||||
{
|
||||
/**
|
||||
* Очищает кеш, связанный с постом.
|
||||
*
|
||||
* @param mixed $entity Пост или связанная сущность
|
||||
* @return void
|
||||
*/
|
||||
private const DEFAULT_TTL = 3600;
|
||||
|
||||
public function clearCache($entity): void
|
||||
{
|
||||
$this->clearAllCacheByModel();
|
||||
}
|
||||
|
||||
public function clearAllCacheByModel(): void
|
||||
{
|
||||
$this->clearCacheByPrefix('tag_ids*');
|
||||
$this->clearCacheByPrefix('tags*');
|
||||
$this->clearCacheByPrefix('tag_content_*');
|
||||
$this->clearTagIdsCache();
|
||||
$this->clearTagsCache();
|
||||
$this->clearTagContentCache();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Получает кешированные данные по ключу.
|
||||
*
|
||||
* @param string $key Ключ кеша
|
||||
* @return mixed
|
||||
*/
|
||||
public function getCachedData(string $key)
|
||||
{
|
||||
return Cache::get($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Кеширует данные по ключу.
|
||||
*
|
||||
* @param string $key Ключ кеша
|
||||
* @param mixed $data Данные для кеширования
|
||||
* @param int $ttl Время жизни кеша в секундах
|
||||
* @return void
|
||||
*/
|
||||
public function cacheData(string $key, $data, int $ttl = 3600): void
|
||||
public function cacheData(string $key, $data, int $ttl = null): void
|
||||
{
|
||||
Cache::put($key, $data, $ttl);
|
||||
Cache::put($key, $data, $ttl ?? self::DEFAULT_TTL);
|
||||
}
|
||||
|
||||
private function clearTagIdsCache(): void
|
||||
{
|
||||
$this->clearCacheByPrefix(CacheKeys::TAG_IDS_PREFIX->value.'*');
|
||||
}
|
||||
|
||||
private function clearTagsCache(): void
|
||||
{
|
||||
$this->clearCacheByPrefix(CacheKeys::TAGS_PREFIX->value.'*');
|
||||
}
|
||||
|
||||
private function clearTagContentCache(): void
|
||||
{
|
||||
$this->clearCacheByPrefix(CacheKeys::TAG_CONTENT_PREFIX->value.'*');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\App\Cache;
|
||||
|
||||
use App\Enums\CacheKeys;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class UserCacheService extends AbstractCacheService implements CacheInterface
|
||||
{
|
||||
private const DEFAULT_TTL = 3600;
|
||||
|
||||
public function clearCache($entity): void
|
||||
{
|
||||
if ($entity instanceof User) {
|
||||
$this->clearAllCacheByModel();
|
||||
}
|
||||
}
|
||||
|
||||
public function clearAllCacheByModel(): void
|
||||
{
|
||||
$this->clearCacheByPrefix(CacheKeys::USER_PREFIX->value.'*');
|
||||
}
|
||||
|
||||
public function getCachedData(string $key)
|
||||
{
|
||||
return Cache::get($key);
|
||||
}
|
||||
|
||||
public function cacheData(string $key, $data, int $ttl = null): void
|
||||
{
|
||||
Cache::put($key, $data, $ttl ?? self::DEFAULT_TTL);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user