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*'); } /** * Получает кешированные данные по ключу. * * @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); } }