hryvinskyi/magento2-page-layout-manager
Composer 安装命令:
composer require hryvinskyi/magento2-page-layout-manager
包简介
Adobe Commerce / Magento 2 Performance optimisation module for avoid entity specific page cache bloat
README 文档
README
This module provides configurable control over entity-specific page layout caching to prevent cache bloat in big stores.
Problem
In Adobe Commerce / Magento 2, when addPageLayoutHandles() is called with entitySpecific = true, it creates
individual cache entries for each entity id or sku (catalog_category_view_id_123.xml or catalog_product_view_id_123.xml or catalog_product_view_sku_test.xml).
In large store setups, this can lead to massive cache growth.
Solution
This module provides two possible configuration:
- Allow Entity-Specific Layout Handles (default: false) - when disabled, blocks all entity-specific layouts like
*_id_*.xml - Use Only Specific Validators (default: true) - When enabled, the entity-specific layout will be added only for validated requests
Composer Installation
composer require hryvinskyi/magento2-page-layout-manager php bin/magento module:enable Hryvinskyi_PageLayoutManager bin/magento setup:upgrade bin/magento setup:di:compile bin/magento cache:clean
Manual Installation
- Create directory
app/code/Hryvinskyi/PageLayoutManager - Download and extract module contents to this directory
- Enable the module:
bin/magento module:enable Hryvinskyi_PageLayoutManager bin/magento setup:upgrade bin/magento setup:di:compile bin/magento cache:clean
Features
CMS Page Layout Management
The module automatically disables entity-specific page layouts for CMS pages to prevent cache bloat:
- Admin Panel: The page layout field is disabled (grayed out) in the CMS page edit form with an informative message
- Frontend: Entity-specific page layouts are not applied to CMS pages - only global/theme-level layouts are used
- Cache Optimization: Prevents creation of separate cache entries for each CMS page layout variation
This ensures consistent layout handling across all CMS pages while significantly reducing cache storage requirements.
Usage
Creating Custom Validators
1. Implement the Validator Interface
<?php namespace MyModule\Model\Validator; use Hryvinskyi\PageLayoutManager\Api\RequestValidatorInterface; class MyCustomValidator implements RequestValidatorInterface { public function isRequestAllowed( array $parameters = [], ?string $defaultHandle = null, array $context = [] ): bool { // Your validation logic here // Return true to allow entity-specific caching // Return false to block it // Example: Allow only specific product pages if ($defaultHandle === 'catalog_product_view') { $productId = $parameters['id'] ?? null; return in_array($productId, [1, 2, 3]); // Only these products } return false; } }
2. Create Parameter Modifier (Optional)
<?php namespace MyModule\Model\Modifier; use Hryvinskyi\PageLayoutManager\Api\ModificationResultInterface; use Hryvinskyi\PageLayoutManager\Api\ParameterModifierInterface; use Hryvinskyi\PageLayoutManager\Model\ModificationResult; class MyCustomParameterModifier implements ParameterModifierInterface { public function modifyParameters( array $parameters, ?string $defaultHandle, array $context = [] ): ModificationResultInterface { // Modify parameters when validator allows request $modifiedParameters = $parameters; $modifiedHandle = $defaultHandle; // Example: Add cache tags for better cache management if ($defaultHandle === 'catalog_product_view') { $modifiedParameters['cache_tags'] = ['product_cache_tag']; $modifiedHandle = 'catalog_product_view_optimized'; } return new ModificationResult( $modifiedParameters, $modifiedHandle, $parameters, // original for comparison $defaultHandle // original for comparison ); } }
3. Register in DI Configuration
<!-- etc/di.xml --> <type name="Hryvinskyi\PageLayoutManager\Model\Strategy\ValidatorStrategy"> <arguments> <argument name="requestValidators" xsi:type="array"> <item name="my_custom_validator" xsi:type="object">MyModule\Model\Validator\MyCustomValidator</item> </argument> <argument name="parameterModifiers" xsi:type="array"> <item name="my_custom_validator" xsi:type="object">MyModule\Model\Modifier\MyCustomParameterModifier</item> </argument> </arguments> </type>
Available Context Data
The $context array contains:
entity_specific: boolean indicating if this is an entity-specific request- Additional data can be passed by the calling code
Available Parameters
The $parameters array contains the same data passed to addPageLayoutHandles():
- Layout handle parameters like
['type' => 'some_type', 'id' => 123]
Contributing
Contributions are welcome! Please ensure:
- All tests pass
- New features include tests
- Code follows SOLID principles
- Documentation is updated
License
Copyright © 2025 Volodymyr Hryvinskyi. All rights reserved.
hryvinskyi/magento2-page-layout-manager 适用场景与选型建议
hryvinskyi/magento2-page-layout-manager 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 9 次下载、GitHub Stars 达 3, 最近一次更新时间为 2025 年 09 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「performance」 「cache」 「layout」 「magento2」 「entity-specific」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 hryvinskyi/magento2-page-layout-manager 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 hryvinskyi/magento2-page-layout-manager 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 hryvinskyi/magento2-page-layout-manager 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
g4 application profiler package
repository php library
CSS/Javascript Minificator, Compressor and Concatenator for TYPO3 - highly configurable frontend asset optimization for CSS/JS merging, minification and compression with optional body parsing, async/defer loading, inline output, data-ignore exclusions, SRI integrity validation/calculation, external
WordPress mu-plugin to remove jQuery Migrate from the list of jQuery dependencies and to allow jQuery to enqueue before </body> instead of in the <head>.
Create link to static resources with cache-breaking segment based on md5 of the file
Laravel 5 - Repositories to the database layer
统计信息
- 总下载量: 9
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 20
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-09-15