chore: adds APC as L1 cache at cache middleware#410
Closed
Conversation
e765a5e to
795df3e
Compare
Contributor
There was a problem hiding this comment.
Pull Request Overview
Introduce APCu-backed L1 cache to reduce Redis hits in the cache middleware and clear APC entries when cache regions are flushed.
- Add App\Utils\Cache\APC utility for APCu get/put and region tracking/clearing.
- Update CacheMiddleware to check APC first, then fall back to Redis; add X-Cache-Result distinctions.
- Update RedisCacheService to clear APC region keys on region flush.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| app/Utils/Cache/APC.php | New APCu cache helper with region tracking and clearing. |
| app/Services/Utils/RedisCacheService.php | Flush APC region when clearing a Redis cache region. |
| app/Http/Middleware/CacheMiddleware.php | Introduce APC L1 lookup, Redis fallback, and response headers reflecting cache tier. |
Comments suppressed due to low confidence (1)
app/Http/Middleware/CacheMiddleware.php:1
- When APC hits in the non-tagged branch, $data is never decoded because $data = $this->decode($encoded) is inside the if(!$wasAPCHit) block. This causes $data to remain null and the 'safe guard' below sets it to an empty array, returning an empty response. Move the decode outside the if(!$wasAPCHit) block (mirroring the tagged branch), e.g., place $data = $this->decode($encoded) after the closing brace so it runs for both APC and Redis paths.
<?php namespace App\Http\Middleware;
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Comment on lines
+25
to
+35
| private static function trackKey(string $regionTag, string $key, int $ttl): void | ||
| { | ||
| try { | ||
| $setKey = self::APC_REGION_PREFIX.$regionTag; | ||
| $list = self::apc()->get($setKey, []); | ||
| if (!\is_array($list)) $list = []; | ||
| $list[$key] = \time() + $ttl; | ||
| if (\count($list) > 10000) { array_shift($list); } | ||
| self::apc()->put($setKey, $list, $ttl); | ||
| } catch (\Throwable $e) { /* ignore */ } | ||
| } |
There was a problem hiding this comment.
[nitpick] The hard-coded 10000 cap is a magic number. Consider extracting it to a class constant (e.g., MAX_KEYS_PER_REGION) or a config value so it can be tuned without code changes.
b4fb00d to
3424ef2
Compare
3424ef2 to
864e81c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.