Skip to content

[6.x] TemplateCaches service#18526

Open
riasvdv wants to merge 5 commits intofeature/pathfrom
feature/template-caches
Open

[6.x] TemplateCaches service#18526
riasvdv wants to merge 5 commits intofeature/pathfrom
feature/template-caches

Conversation

@riasvdv
Copy link
Contributor

@riasvdv riasvdv commented Mar 9, 2026

No description provided.

Copy link

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 introduces a new Laravel-scoped TemplateCaches service in src/ with a collector-based architecture for caching template fragments (dependencies, resources, and legacy Yii2 asset bundles), and migrates legacy Yii2-adapter services/tests to use or integrate with it.

Changes:

  • Added CraftCms\Cms\View\TemplateCaches plus a CacheCollectorInterface, TemplateCacheContext, and RegisterTemplateCacheCollectors event to support pluggable cache payload collection/apply.
  • Implemented core collectors (DependencyCollector, ResourceCollector) and a Yii2-adapter collector (LegacyAssetBundleCollector) wired via Yii2ServiceProvider.
  • Updated Twig cache node compilation output and added unit tests + Yii2-adapter tests to validate collector registration and replay behavior.

Reviewed changes

Copilot reviewed 29 out of 29 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/View/TemplateCaches.php New template fragment cache service; stores collector payloads and dependency info.
src/View/CacheCollectors/DependencyCollector.php New dependency/tag+expiry collection and nesting merge behavior.
src/View/CacheCollectors/ResourceCollector.php Captures/reapplies HtmlStack buffered resources for cached fragments.
src/View/Contracts/CacheCollectorInterface.php Collector contract for begin/end/apply.
src/View/Data/TemplateCacheContext.php Context passed to collectors (cacheKey/global/resources).
src/View/Events/RegisterTemplateCacheCollectors.php Event to register additional collectors.
src/Twig/Nodes/CacheNode.php Compiles to resolve cache service from the container.
tests/Unit/View/TemplateCachesTest.php Unit tests for collector event dispatch, payload application, and scoping.
tests/Unit/View/DependencyCollectorTest.php Unit tests for dependency collector nesting and expiry selection.
tests/Unit/View/ResourceCollectorTest.php Unit tests for capturing and replaying buffered resources.
tests/Unit/Http/RequestMixinTest.php Tests for Request macro behavior after moving to a mixin class.
src/Providers/AppServiceProvider.php Replaces inline Request macros with RequestMixin.
src/Http/Mixins/RequestMixin.php Centralizes Request macro implementations.
yii2-adapter/legacy/services/TemplateCaches.php Deprecates legacy service and delegates to new TemplateCaches.
yii2-adapter/legacy/services/Elements.php Routes element cache info collection through DependencyCollector.
yii2-adapter/src/View/LegacyAssetBundleCollector.php Collector to capture/replay legacy Yii2 asset bundle registrations.
yii2-adapter/src/Yii2ServiceProvider.php Registers legacy collector via RegisterTemplateCacheCollectors event.
yii2-adapter/tests-laravel/View/*.php Yii2-adapter tests covering collector registration and asset bundle replay.
yii2-adapter/tests-laravel/Pest.php Includes new View test folder.
tests/.pest/snapshots/...CacheNodeTest/*.snap Snapshot updates for new compiled cache service resolution.
src/Element/Queries/Concerns/HydratesElements.php Uses DependencyCollector for expiry date collection while hydrating.
src/Element/Queries/Concerns/CollectsCacheTags.php Uses DependencyCollector for collecting query cache tags.

💡 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 9, 2026 12:09
@riasvdv riasvdv requested a review from brandonkelly March 9, 2026 12:09
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.

2 participants