diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index 0410285..60ef7b3 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -42,7 +42,6 @@ class Kernel extends HttpKernel 'api' => [ 'throttle:api', \Illuminate\Routing\Middleware\SubstituteBindings::class, - \App\Http\Middleware\CompressionMiddleware::class, ], ]; diff --git a/app/Repositories/BaseCachedRepository.php b/app/Repositories/BaseCachedRepository.php index d0423eb..8c32f12 100644 --- a/app/Repositories/BaseCachedRepository.php +++ b/app/Repositories/BaseCachedRepository.php @@ -47,6 +47,7 @@ abstract class BaseCachedRepository extends BaseRepository { $result = parent::update($id, $data); $this->clearCache(); + Cache::forget($this->getCacheKey($id)); return $result; } @@ -54,6 +55,7 @@ abstract class BaseCachedRepository extends BaseRepository { $result = parent::delete($id); $this->clearCache(); + Cache::forget($this->getCacheKey($id)); return $result; } @@ -70,7 +72,15 @@ abstract class BaseCachedRepository extends BaseRepository } public function clearCache() { - Cache::flush(); + // Chỉ xóa cache của repository này, không flush toàn bộ cache app + $keysToForget = [ + $this->getCacheKey('getAll'), + $this->getCacheKey('getCount'), + ]; + + foreach ($keysToForget as $key) { + Cache::forget($key); + } } public function clearCacheByKey(string $key) {