refactor: remove compression middleware from API routes and optimize cache invalidation in BaseCachedRepository.
This commit is contained in:
@@ -42,7 +42,6 @@ class Kernel extends HttpKernel
|
|||||||
'api' => [
|
'api' => [
|
||||||
'throttle:api',
|
'throttle:api',
|
||||||
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||||
\App\Http\Middleware\CompressionMiddleware::class,
|
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ abstract class BaseCachedRepository extends BaseRepository
|
|||||||
{
|
{
|
||||||
$result = parent::update($id, $data);
|
$result = parent::update($id, $data);
|
||||||
$this->clearCache();
|
$this->clearCache();
|
||||||
|
Cache::forget($this->getCacheKey($id));
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,6 +55,7 @@ abstract class BaseCachedRepository extends BaseRepository
|
|||||||
{
|
{
|
||||||
$result = parent::delete($id);
|
$result = parent::delete($id);
|
||||||
$this->clearCache();
|
$this->clearCache();
|
||||||
|
Cache::forget($this->getCacheKey($id));
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,7 +72,15 @@ abstract class BaseCachedRepository extends BaseRepository
|
|||||||
}
|
}
|
||||||
public function clearCache()
|
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)
|
public function clearCacheByKey(string $key)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user