-
-
Notifications
You must be signed in to change notification settings - Fork 553
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[5.x] Static cache response statuses (#10334)
- Loading branch information
1 parent
55f92fb
commit 52f8508
Showing
4 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace Statamic\StaticCaching; | ||
|
||
enum ResponseStatus | ||
{ | ||
case HIT; | ||
case MISS; | ||
case UNDEFINED; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace Statamic\StaticCaching; | ||
|
||
use Illuminate\Http\Response; | ||
|
||
class ResponseStatusTracker | ||
{ | ||
private array $responses = []; | ||
|
||
public function set(Response $response, ResponseStatus $status): void | ||
{ | ||
$this->responses[spl_object_id($response)] = $status; | ||
} | ||
|
||
public function get(Response $response): ResponseStatus | ||
{ | ||
return $this->responses[spl_object_id($response)] ?? ResponseStatus::UNDEFINED; | ||
} | ||
|
||
public function registerMacros(): void | ||
{ | ||
$tracker = $this; | ||
|
||
Response::macro('setStaticCacheResponseStatus', fn ($status) => $tracker->set($this, $status)); | ||
|
||
Response::macro('staticCacheResponseStatus', fn () => $tracker->get($this)); | ||
|
||
Response::macro('wasStaticallyCached', fn () => $this->staticCacheResponseStatus() === ResponseStatus::HIT); | ||
} | ||
} |
This file contains 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