Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR extracts element-cache collection/invalidation logic into a dedicated ElementCaches service (plus facade), ports legacy craft\services\Elements cache APIs to delegate to it (now deprecated), and updates call sites across the CMS + yii2 adapter to use the new service while preserving legacy Yii event compatibility.
Changes:
- Added
CraftCms\Cms\Element\ElementCaches, facadeCraftCms\Cms\Support\Facades\ElementCaches, and eventCraftCms\Cms\Element\Events\InvalidateElementCaches. - Refactored core services, legacy yii2-adapter services/controllers, template support, and queries to use the new cache APIs.
- Added feature tests for the extracted cache service and updated changelog entries for the deprecations.
Reviewed changes
Copilot reviewed 34 out of 34 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| yii2-adapter/src/Event/EventCompatibility.php | Registers legacy Elements::registerEvents() to bridge new invalidation events back to Yii handlers. |
| yii2-adapter/legacy/services/Tags.php | Uses ElementCaches facade for tag cache invalidation. |
| yii2-adapter/legacy/services/Globals.php | Uses ElementCaches facade for global invalidation. |
| yii2-adapter/legacy/services/Elements.php | Deprecates cache APIs and delegates to extracted service; bridges invalidation events to legacy Yii event. |
| yii2-adapter/legacy/services/Categories.php | Uses ElementCaches facade for category cache invalidation. |
| yii2-adapter/legacy/events/InvalidateElementCachesEvent.php | Marks legacy event as deprecated in favor of new event class. |
| yii2-adapter/legacy/elements/db/ElementQuery.php | Switches cache-collection calls to ElementCaches facade during query hydration/prepare. |
| yii2-adapter/legacy/controllers/NestedElementsController.php | Uses ElementCaches facade to invalidate caches for reordered owners. |
| tests/Feature/Element/Queries/EntryQueryTest.php | Updates cache-collection calls to new facade. |
| tests/Feature/Element/Queries/Concerns/QueriesNestedElementsTest.php | Updates cache-collection calls to new facade. |
| tests/Feature/Element/Queries/Concerns/QueriesEagerlyTest.php | Uses new invalidation API before eager-loading tests. |
| tests/Feature/Element/Queries/Concerns/CollectsCacheTagsTest.php | Updates cache-collection calls to new facade. |
| tests/Feature/Element/Queries/Concerns/CachesQueriesTest.php | Uses new element-type invalidation API for cached query tests. |
| tests/Feature/Element/Queries/AssetQueryTest.php | Updates cache-collection calls to new facade. |
| tests/Feature/Element/ElementCachesTest.php | Adds new feature coverage for cache collection + invalidation tag normalization behavior. |
| src/User/Users.php | Injects ElementCaches and uses it for user-type invalidation. |
| src/User/UserGroups.php | Injects ElementCaches and uses it for user-type invalidation on group changes. |
| src/User/Elements/User.php | Uses ElementCaches facade for entry cache invalidation in delete flow. |
| src/Support/Template.php | Uses ElementCaches facade when Twig attribute access touches an element. |
| src/Support/Facades/ElementCaches.php | Adds facade for convenient static access to ElementCaches. |
| src/Structure/Structures.php | Injects ElementCaches and uses it to invalidate caches after structure mutations. |
| src/Site/Sites.php | Injects ElementCaches and invalidates caches on site config changes. |
| src/Section/Sections.php | Injects ElementCaches and invalidates entry caches on section changes. |
| src/Image/ImageTransforms.php | Injects ElementCaches and invalidates asset caches on transform changes. |
| src/Gql/Gql.php | Injects ElementCaches for cache tag collection during GraphQL execution/caching. |
| src/GarbageCollection/GarbageCollection.php | Injects ElementCaches and invalidates all element caches after GC run. |
| src/Field/Fields.php | Injects ElementCaches and invalidates all caches on field save/delete. |
| src/Entry/EntryTypes.php | Injects ElementCaches and invalidates entry caches on entry type changes. |
| src/Element/Events/InvalidateElementCaches.php | Introduces the new invalidation event payload class. |
| src/Element/ElementCaches.php | Introduces extracted cache collection/invalidation service and emits invalidation events. |
| src/Element/Concerns/Structurable.php | Uses ElementCaches facade to invalidate caches after structure moves. |
| src/Asset/Volumes.php | Injects ElementCaches and invalidates asset caches on volume changes. |
| src/Address/Addresses.php | Injects ElementCaches and invalidates address caches on field layout changes. |
| CHANGELOG-WIP.md | Documents new service/facade and deprecations of legacy Elements cache methods. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Description
Extract a new ElementCaches service that ports all cache related methods from the legacy Elements service