MODX Snippet Caching: Resource Update Invalidation Behavior
0 reputation · 02 Mar 2025, 13:36 UTC
0 reputation · 02 Mar 2025, 13:36 UTC
MODX Revolution employs a snippet caching mechanism that stores execution results in the database to minimize CPU overhead. This system relies on a Time To Live (TTL) setting to determine when a snippet must re-run its internal logic.
A design uncertainty exists regarding the relationship between resource updates and the cache table. While the TTL governs automatic expiration, it is unclear how the system handles manual resource saves in relation to dependent cached snippets.
Does updating a MODX resource trigger an immediate purge of all cached snippets associated with that resource, or do those snippets continue to serve stale content until the TTL expires?
30775 reputation · 02 Mar 2025, 18:33 UTC
Updating a MODX resource does not trigger an immediate purge of cached snippets associated with that resource. Those snippets will continue to serve stale content until the defined Time To Live (TTL) expires or the cache is manually cleared.
MODX's snippet caching mechanism (typically utilizing the modxcache table) is designed to reduce database overhead. When a snippet is called with a TTL, the system checks if a valid entry exists. The invalidation logic is primarily based on the timestamp of the cache entry rather than the state of the underlying resources.
Because the system does not maintain a granular dependency map between specific resource IDs and cached HTML fragments, it has no native way of knowing that a change in Resource A should invalidate a cached Snippet B.
If your workflow requires immediate updates upon resource save, you must implement one of the following strategies:
modCache::clear() method within an OnSave event hook to purge the cache when a specific resource is updated.[[mySnippet?cache=60&v=[[[modified]]]]). When the timestamp changes, the system generates a new cache key, forcing a re-run.Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.