Skip to content

Cache Tweaks: Reduces Redis Layout Cache via Generic Handles

User Guide


CopeX GmbH
Web: https://copex.io
Email: office@copex.io


Inhaltsverzeichnis / Table of Contents

Abschnitt / Section Seite
1 Was es macht / What it does 3
2 Wann sinnvoll / When to use 3
3 Voraussetzungen / Requirements 4
4 Installation 4
5 Aktivierung / Activation 5
6 Verwendung / Usage 5
7 Was tun bei Problemen / Troubleshooting 6
8 Für Entwickler / For Developers 7

1 What it does

Magento generates dedicated layout handles for every product page — for example CATALOG_PRODUCT_VIEW_SKU_24-MB01 and CATALOG_PRODUCT_VIEW_ID_42. This means one Redis layout cache entry per SKU. With a catalogue of 50,000 products the layout cache becomes enormous, Redis lookups slow down, and memory consumption grows unnecessarily.

This module intercepts handle generation at the source: it strips the id and sku keys from layout-handle parameters and replaces entity-specific handles with generic ones. The result is a small, stable layout cache that stays fast even for large catalogues.


2 When to use

  • Large product catalogue (roughly 10,000+ products)
  • Redis layout cache grows noticeably or consumes too much memory
  • Layout cache lookups are slow according to Redis monitoring
  • Redis evictions occur despite sufficient configured memory

3 Requirements

  • Magento 2.4.x
  • PHP 8.1 or higher (compatible with 8.2, 8.3, 8.4, 8.5)
  • copex/module-core >1.1.0

4 Installation

composer require copex/module-performance-tweaks
bin/magento module:enable CopeX_Performance
bin/magento setup:upgrade
bin/magento cache:flush

Alternatively, install the complete suite:

composer require copex/performance-suite-bundle

5 Activation

Stores → Configuration → Advanced → Performance → Cache

Option Function
Disable Entity Specific Layout Handles Removes entity-specific handles (e.g. CATALOG_PRODUCT_VIEW_TYPE_SIMPLE)
Disable Entity ID Layout Handles Removes ID- and SKU-specific handles (e.g. CATALOG_PRODUCT_VIEW_SKU_MH01)

Both options default to Yes.


6 Usage

Cache Tweaks works entirely in the background — no CLI commands required. The module is active immediately after enabling and flushing the cache.

To verify: flush the layout cache and let it rebuild through normal traffic. With both options enabled, the number of layout cache entries grows only with page types (category, product, cart), not with the number of products.


7 Troubleshooting

Disable the options:

Stores → Configuration → Advanced → Performance → Cache → set both options to "No", then flush the cache. The module becomes a no-op — all handles are generated as Magento standard.

Disable individual options:

  • Only disable "Disable Entity ID Layout Handles": SKU and ID handles are generated again; entity-specific handles remain disabled.
  • Only disable "Disable Entity Specific Layout Handles": SKU/ID keys are still removed; the $entitySpecific flag is no longer overridden.

Layout issues after activation:

If a theme or module strictly requires SKU- or ID-specific layout handles, set both options to "No" and adapt the theme or module to use generic handles instead.


8 For Developers

The module registers a before plugin on Magento\Framework\View\Result\Page::addPageLayoutHandles. The plugin reads configuration once in the constructor (store scope) and is stateless afterwards.

Adjusting sort order in DI XML:

<type name="Magento\Framework\View\Result\Page">
    <plugin name="copex_performance_remove_entity_cache"
            type="CopeX\Performance\Plugin\RemoveEntityCache"
            sortOrder="10"/>
</type>

Plugins with a lower sortOrder run before Cache Tweaks and see the original parameters. Plugins with a higher sortOrder see the already-stripped parameters.


CopeX GmbH — Web: https://copex.io — Email: office@copex.io