refactor: remove compression middleware from API routes and optimize cache invalidation in BaseCachedRepository.
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user