Skip to content

Commit ee6ece9

Browse files
koriymclaude
andcommitted
docs: Clarify behavior difference between Cacheable and non-Cacheable classes
- Explain automatic binding for Cacheable classes (CommandInterceptor) - Explain explicit attribute requirement for non-Cacheable classes (RefreshInterceptor) - Cross-reference related interceptors in documentation - Address review comment: #167 (comment) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent ec6327c commit ee6ece9

4 files changed

Lines changed: 22 additions & 11 deletions

File tree

src-annotation/Purge.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,19 @@
99
/**
1010
* Purges cache for specified URI after command execution
1111
*
12+
* Behavior differs based on class attributes:
13+
* - **#[Cacheable] classes**: CommandInterceptor automatically binds to all
14+
* command methods (onPut/onPatch/onDelete) and processes #[Purge] annotations
15+
* - **Non-Cacheable classes**: RefreshInterceptor binds only to methods explicitly
16+
* marked with #[Purge] or #[Refresh]
17+
*
1218
* Example:
1319
* ```php
1420
* #[Purge(uri: 'app://self/user/profile?user_id={id}')]
1521
* #[Purge(uri: 'app://self/user/friend?user_id={id}')]
1622
* public function onDelete(int $id): static
1723
* ```
1824
*
19-
* Interceptors bound:
20-
* - RefreshInterceptor (when applied to non-Cacheable classes)
21-
* - CommandInterceptor (when applied to Cacheable classes)
22-
*
2325
* @see https://bearsunday.github.io/manuals/1.0/en/cache.html#tag-based-cache-invalidation
2426
*/
2527
#[Attribute(Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]

src-annotation/Refresh.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,18 @@
99
/**
1010
* Refreshes cache for specified URI after command execution
1111
*
12+
* Behavior differs based on class attributes:
13+
* - **#[Cacheable] classes**: CommandInterceptor automatically binds to all
14+
* command methods (onPut/onPatch/onDelete) and processes #[Refresh] annotations
15+
* - **Non-Cacheable classes**: RefreshInterceptor binds only to methods explicitly
16+
* marked with #[Purge] or #[Refresh]
17+
*
1218
* Example:
1319
* ```php
1420
* #[Refresh(uri: 'app://self/user/profile?user_id={id}')]
1521
* public function onPut(int $id, string $name): static
1622
* ```
1723
*
18-
* Interceptors bound:
19-
* - RefreshInterceptor (when applied to non-Cacheable classes)
20-
* - CommandInterceptor (when applied to Cacheable classes)
21-
*
2224
* @see https://bearsunday.github.io/manuals/1.0/en/cache.html#event-driven-content
2325
*/
2426
#[Attribute(Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]

src/CommandInterceptor.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@
1515
/**
1616
* Interceptor for cache invalidation on CQRS commands with #[Purge] or #[Refresh]
1717
*
18-
* Bound to command methods (onPut/onPatch/onDelete) of #[Cacheable] classes.
19-
* Executes cache invalidation after successful write operations.
18+
* Automatically bound to all command methods (onPut/onPatch/onDelete) of #[Cacheable] classes.
19+
* Processes #[Purge] and #[Refresh] annotations on these methods and executes cache
20+
* invalidation after successful write operations.
21+
*
22+
* For non-Cacheable classes, use RefreshInterceptor instead by explicitly marking methods
23+
* with #[Purge] or #[Refresh].
2024
*
2125
* @see \BEAR\RepositoryModule\Annotation\Purge
2226
* @see \BEAR\RepositoryModule\Annotation\Refresh

src/RefreshInterceptor.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414
/**
1515
* Interceptor for cache refresh commands with #[Purge] or #[Refresh]
1616
*
17-
* Bound to methods marked with #[Purge] or #[Refresh] on non-Cacheable classes.
17+
* Bound only to methods explicitly marked with #[Purge] or #[Refresh] on non-Cacheable classes.
18+
* Unlike CommandInterceptor (which automatically binds to all command methods of #[Cacheable]
19+
* classes), this interceptor requires explicit attribute annotation on each method.
20+
*
1821
* Executes cache invalidation commands after successful method execution.
1922
*
2023
* @see \BEAR\RepositoryModule\Annotation\Purge

0 commit comments

Comments
 (0)