refactor: remove compression middleware from API routes and optimize cache invalidation in BaseCachedRepository.

This commit is contained in:
pbao9
2026-03-16 17:21:21 +07:00
parent b5c81cf23c
commit 50a5bfd530
2 changed files with 11 additions and 2 deletions
+11 -1
View File
@@ -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)
{