This commit is contained in:
f4ilji
2025-01-30 00:31:40 +05:00
parent bad611eb84
commit 3385dc5807
60 changed files with 1811 additions and 825 deletions
@@ -0,0 +1,48 @@
<?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);
}
}
+6 -2
View File
@@ -18,14 +18,18 @@ class PostCacheService extends AbstractCacheService implements CacheInterface
$cacheKeyBySlug = md5($entity->slug);
$cacheKeyById = md5($entity->id);
Cache::forget($cacheKeyBySlug);
Cache::forget($cacheKeyById);
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*');
}
/**