Skip to content

Commit cea6aa1

Browse files
committed
docs: Add usage examples to cache attributes
- Add practical examples to HttpCache, Cacheable, Purge, Refresh - Add class-level examples to DonutCache and CacheableResponse - Show URI template placeholders usage in Purge/Refresh - Demonstrate CDN cache configuration patterns in HttpCache
1 parent e6aa727 commit cea6aa1

6 files changed

Lines changed: 59 additions & 0 deletions

File tree

src-annotation/Cacheable.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@
1313
* For event-driven cache invalidation based on resource dependencies, use
1414
* #[CacheableResponse] or #[DonutCache] instead.
1515
*
16+
* Example:
17+
* ```php
18+
* // Cache for 1 hour
19+
* #[Cacheable(expirySecond: 3600)]
20+
*
21+
* // Cache with predefined expiry preset
22+
* #[Cacheable(expiry: 'short')] // short, medium, long, never
23+
*
24+
* // Cache until specific time from body field
25+
* #[Cacheable(expiryAt: 'expires_at')]
26+
* ```
27+
*
1628
* Interceptors bound:
1729
* - CacheInterceptor (onGet methods)
1830
* - CommandInterceptor (onPut/onPatch/onDelete methods)

src-annotation/CacheableResponse.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,18 @@
1616
* The entire response is cached and receives an ETag for conditional requests,
1717
* enabling 304 (Not Modified) responses to reduce network transfer costs.
1818
*
19+
* Example:
20+
* ```php
21+
* #[CacheableResponse]
22+
* class Article extends ResourceObject
23+
* {
24+
* public function onGet(int $id): static
25+
*
26+
* #[RefreshCache]
27+
* public function onDelete(int $id): static
28+
* }
29+
* ```
30+
*
1931
* Interceptors bound:
2032
* - DonutCacheableResponseInterceptor (onGet methods when applied to class)
2133
* - DonutCommandInterceptor (onPut/onPatch/onDelete methods when applied to class)

src-annotation/DonutCache.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@
1515
* which uses TTL-based expiration, this enables tag-based invalidation. Only
1616
* cacheable portions are stored; no ETag is generated for the entire response.
1717
*
18+
* Example:
19+
* ```php
20+
* #[DonutCache]
21+
* class BlogPosting extends ResourceObject
22+
* {
23+
* #[Embed(rel: 'comment', src: 'app://self/comments')]
24+
* public function onGet(int $id): static
25+
* }
26+
* ```
27+
*
1828
* Interceptors bound:
1929
* - DonutCacheInterceptor (onGet methods when applied to class, or any method when applied to method)
2030
*

src-annotation/HttpCache.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@
1515
*
1616
* Builds a complex Cache-Control header
1717
*
18+
* Example:
19+
* ```php
20+
* // CDN cache for 1 hour, browser cache for 5 minutes
21+
* #[HttpCache(maxAge: 300, sMaxAge: 3600)]
22+
*
23+
* // Private cache with revalidation
24+
* #[HttpCache(isPrivate: true, mustRevalidate: true, maxAge: 60)]
25+
*
26+
* // No caching (use NoHttpCache instead for simplicity)
27+
* #[HttpCache(noCache: true, noStore: true)]
28+
* ```
29+
*
1830
* Interceptors bound:
1931
* - HttpCacheInterceptor (onGet methods)
2032
*

src-annotation/Purge.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@
99
/**
1010
* Purges cache for specified URI after command execution
1111
*
12+
* Example:
13+
* ```php
14+
* #[Purge(uri: 'app://self/user/profile?user_id={id}')]
15+
* #[Purge(uri: 'app://self/user/friend?user_id={id}')]
16+
* public function onDelete(int $id): static
17+
* ```
18+
*
1219
* Interceptors bound:
1320
* - RefreshInterceptor (when applied to non-Cacheable classes)
1421
* - CommandInterceptor (when applied to Cacheable classes)

src-annotation/Refresh.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
/**
1010
* Refreshes cache for specified URI after command execution
1111
*
12+
* Example:
13+
* ```php
14+
* #[Refresh(uri: 'app://self/user/profile?user_id={id}')]
15+
* public function onPut(int $id, string $name): static
16+
* ```
17+
*
1218
* Interceptors bound:
1319
* - RefreshInterceptor (when applied to non-Cacheable classes)
1420
* - CommandInterceptor (when applied to Cacheable classes)

0 commit comments

Comments
 (0)