VOOZH about

URL: https://deepwiki.com/MahoCommerce/maho/5.1-caching-system

⇱ Caching System | MahoCommerce/maho | DeepWiki


Loading...
Last indexed: 15 May 2026 (ea8ab8)
Menu

Caching System

Purpose and Scope

This document describes Maho's multi-layered caching system, which optimizes performance by storing frequently accessed data in memory or on disk. The caching system encompasses configuration caching, layout caching, block output caching, and specialized caches for minified assets and images. It leverages modern PHP 8.3+ features and integrates with Symfony's caching components.


Architecture Overview

Maho's caching system reduces database queries and expensive operations by storing computed results. The system supports multiple backend storage engines (via Symfony Cache) and tag-based invalidation for granular cache control.

Cache System Architecture


Sources: app/Mage.php236-245 app/code/core/Mage/Core/etc/config.xml114-120 app/code/core/Mage/Core/Helper/Minify.php19-26 composer.json57


Cache Types and Management

Maho categorizes cached data into types, allowing administrators to refresh specific parts of the system without a full flush. These types are defined in app/code/core/Mage/Core/etc/config.xml.

Core Cache Types

Cache TypeCodeTagDescription
ConfigurationconfigCONFIGSystem and module XML files app/code/core/Mage/Core/etc/config.xml116-120
LayoutslayoutLAYOUT_GENERAL_CACHE_TAGLayout building instructions app/code/core/Mage/Core/etc/config.xml121-125
Blocks HTMLblock_htmlBLOCK_HTMLPage blocks HTML output app/code/core/Mage/Core/etc/config.xml126-130
TranslationstranslateTRANSLATEMerged translation files app/code/core/Mage/Core/etc/config.xml131-135
CollectionscollectionsCOLLECTION_DATADatabase collection results app/code/core/Mage/Core/etc/config.xml136-140
IconsiconsICONSSVG icons library app/code/core/Mage/Core/etc/config.xml141-145

Administrative Control

The Mage_Adminhtml_CacheController provides actions to manage these caches via the Admin Panel.

Sources: app/code/core/Mage/Adminhtml/controllers/CacheController.php13-205 app/code/core/Mage/Core/etc/config.xml114-146 app/code/core/Mage/Core/etc/system.xml59-75


Configuration Caching

The configuration cache is critical for performance, storing the merged XML tree from all active modules and database overrides.

Application Initialization

During bootstrap, Mage_Core_Model_App::init() calls _initCache() to prepare the caching engine before loading the full module configuration app/code/core/Mage/Core/Model/App.php259-260

Cache Save Locking

To prevent race conditions where multiple processes attempt to write the configuration cache simultaneously, Maho employs a locking mechanism:

  1. Acquisition: Acquires a named lock Mage::getConfig()->getCacheSaveLock(30, true) before writing app/code/core/Mage/Adminhtml/controllers/CacheController.php62
  2. Ban Use: Temporarily bans the use of 'config' cache during reinitialization app/code/core/Mage/Adminhtml/controllers/CacheController.php60
  3. Release: Releases the lock after the write operation is complete via releaseCacheSaveLock() app/code/core/Mage/Adminhtml/controllers/CacheController.php71

Sources: app/code/core/Mage/Core/Model_App.php248-272 app/code/core/Mage/Adminhtml/controllers/CacheController.php58-76


Asset Minification Caching

Maho includes a specialized caching system for CSS and JavaScript minification via Mage_Core_Helper_Minify.

Processing Logic

When minification is enabled, the system processes assets and stores them in public/media/mahominify/. Mage_Page_Block_Html_Head marks items for minification if they are not in the admin area app/code/core/Mage/Page/Block/Html/Head.php111-121

Minification Flow


Key Features

Sources: app/code/core/Mage/Core/Helper/Minify.php17-210 app/code/core/Mage/Page/Block/Html/Head.php111-121


Invalidation Strategies and Observers

Maho uses its event-observer system to invalidate caches when data changes. Modern observers are registered via PHP attributes.

Cron Status Caching

Maho caches the last cron status check to avoid expensive database lookups on every admin page load. It uses the crontab tag and a specific key cron_last_status_check app/code/core/Mage/Cron/Model/Observer.php15-17 The check occurs in checkCronStatus app/code/core/Mage/Cron/Model/Observer.php36-68 which is registered as an observer using the #[Maho\Config\Observer] attribute app/code/core/Maho/Config/Observer.php13

Event-Driven Cache Management

Observers react to system changes to update or clear related data:

Data Flow: Admin Cache Management UI


Sources: app/code/core/Mage/Adminhtml/controllers/CacheController.php126-141 app/code/core/Mage/Cron/Model/Observer.php15-68 app/code/core/Mage/Core/etc/config.xml114-146 lib/Maho/Config/Observer.php13