-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathCacheableResponse.php
More file actions
48 lines (44 loc) · 1.33 KB
/
CacheableResponse.php
File metadata and controls
48 lines (44 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
declare(strict_types=1);
namespace BEAR\RepositoryModule\Annotation;
use Attribute;
use BEAR\QueryRepository\DonutCacheModule;
/**
* Enables event-driven cache invalidation for fully cacheable responses
*
* For content that is fundamentally static but changes predictably via resource
* methods (onPut, onDelete, etc.). Unlike #[Cacheable] which uses TTL-based
* expiration, this enables tag-based invalidation driven by resource dependencies.
* The entire response is cached and receives an ETag for conditional requests,
* enabling 304 (Not Modified) responses to reduce network transfer costs.
*
* Example:
* ```php
* #[CacheableResponse]
* class Article extends ResourceObject
* {
* public function onGet(int $id): static
* {
* // ...
* }
*
* #[RefreshCache]
* public function onDelete(int $id): static
* {
* // ...
* }
* }
* ```
*
* Interceptors bound:
* - DonutCacheableResponseInterceptor (onGet methods when applied to class)
* - DonutCommandInterceptor (onPut/onPatch/onDelete methods when applied to class)
* - DonutCacheInterceptor (when applied to method)
*
* @see DonutCacheModule
* @see https://bearsunday.github.io/manuals/1.0/en/cache.html#event-driven-content
*/
#[Attribute(Attribute::TARGET_METHOD | Attribute::TARGET_CLASS)]
final class CacheableResponse
{
}