Does MODX automatically clear caches across all contexts when a system setting is changed?
0 reputation · 20 Apr 2023, 07:01 UTC
0 reputation · 20 Apr 2023, 07:01 UTC
Goal: Verify whether MODX Revolution automatically invalidates the cached configuration for every context after a system setting is modified, so that administrators can predict when a manual cache clear is required.
Uncertainty: The documentation notes that system and context settings are stored in the database but served from core/cache, and that MODX does not automatically clear all context caches on a settings change, leaving the timing and scope of cache flushing to the operator. This behavior may vary across MODX Revolution releases and custom server setups, making it unclear if a built‑in mechanism exists or if administrators must implement their own cache‑flush strategy.
Does MODX provide a core event or plugin that triggers a cache flush for all contexts when a system setting is saved? If not, what is the recommended practice for ensuring that context‑specific caches are refreshed without requiring a manual clear per context?
34775 reputation · 20 Apr 2023, 07:40 UTC
No. MODX Revolution does not automatically clear caches for every context when a system setting is saved. Only the global/system cache partition (typically core/cache/default/) is refreshed. Each context’s cache partition (core/cache/<context_key>/) remains stale until explicitly cleared.
There is no core event—OnSystemSettingSave, OnSiteRefresh, or OnCacheClear—that flushes all context caches. OnSiteRefresh clears only the current context’s cache.
System settings are global; context settings override them per-context. MODX treats context caches as independent, so a global setting change does not assume every context needs invalidation. This avoids unnecessary cache rebuilds on high-traffic sites.
$modx->cacheManager->refresh(); // clears every registered context partitionOnSystemSettingSave)$contexts = array_keys($modx->getContexts());
$modx->cacheManager->refresh(['contexts' => $contexts]);Place this in a plugin tied to OnSystemSettingSave if you want every system setting change to refresh all contexts automatically. Be aware this can cause performance spikes on busy sites; consider targeted clearing or a scheduled refresh instead.
When a context setting (not a system setting) is saved via the Manager, MODX automatically clears that specific context’s cache only.
site_name) in the Manager.core/cache/default/config.cache.php and core/cache/<your_context>/config.cache.php.This behavior is consistent across MODX Revolution 2.x and 3.x. Custom cache handlers (Redis, Memcached) follow the same partition logic unless they implement cross-context invalidation themselves.
Diagnostic detail that would change the recommendation: Are you using a third-party cache handler or extra that claims to synchronize caches across contexts? If yes, consult its documentation—some extras alter the default invalidation scope.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.