Skip to content

[6.x] ElementCaches#18647

Merged
brandonkelly merged 6 commits into6.xfrom
feature/element-caches
Mar 31, 2026
Merged

[6.x] ElementCaches#18647
brandonkelly merged 6 commits into6.xfrom
feature/element-caches

Conversation

@riasvdv
Copy link
Copy Markdown
Contributor

@riasvdv riasvdv commented Mar 30, 2026

Description

Extract a new ElementCaches service that ports all cache related methods from the legacy Elements service

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, facade CraftCms\Cms\Support\Facades\ElementCaches, and event CraftCms\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.

@riasvdv riasvdv marked this pull request as ready for review March 30, 2026 14:08
@riasvdv riasvdv requested a review from brandonkelly March 30, 2026 14:08
Base automatically changed from feature/element-helper to 6.x March 30, 2026 22:09
@brandonkelly brandonkelly merged commit 1b73ffa into 6.x Mar 31, 2026
16 checks passed
@brandonkelly brandonkelly deleted the feature/element-caches branch March 31, 2026 21:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants