The MODx Cache

The MODx cache (pronounced "cash") is just a temporary storage area that MODx uses to store frequently used information. When MODx renders a document, it has often has to perform a number of tasks behind the scenes before the document is sent to the browser. When a document is marked as "Cacheable," MODx stores the result in the cache so that the next time the document is requested, it can serve up the cached version without performing all the background operations.

It's important to be aware of the cache because, if you change a document in the MODx Manager, the changes won't show up in the "front end" until the cache is cleared. You can prevent this by making sure the Empty cache? checkbox is checked on the document's Page settings tab. When the checkbox is checked, MODx will clear the cache every time that document is saved after being edited.

You should designate a document as cached when the content of the document won't change unless you edit it yourself. That way, the page will take less time to load.

If a snippet on the page produces information that changes every time the page is visited, MODx gives you the option of letting you call the snippet as uncached in a cached page. That way, MODx can cache the rest of the page and fill in the results produced by the snippet every time the page is called.

It is a quirk of MODx Evolution that when you have a document designated as uncached (the cacheable? checkbox is unchecked) and you put an uncached snippet tag on that page, the snippet is actually called cached so the results the user sees may be out of date. The same thing happens with snippets that call other snippets. If the snippet is uncached and calls a second snippet, also uncached, a cached version of the second snippet will be served up. Just remember that when moving from container to contained item, the effect of the cached designation reverses. Generally, you can avoid this by having the page designated as cacheable and call any snippets on the page cached. Snippets called by those snippets should generally be uncached. Note that this issue does not exist in MODx Revolution.
 

 

My book, MODX: The Official Guide - Digital Edition is now available here. The paper version of the book is available from Amazon.

If you have the book and would like to download the code, you can find it here.

If you have the book and would like to see the updates and corrections page, you can find it here.

MODX: The Official Guide is 772 pages long and goes far beyond this web site in explaining beginning and advanced MODX techniques. It includes detailed information on:

  • Installing MODX
  • How MODX Works
  • Working with MODX resources and Elements
  • Using Git with MODX
  • Using common MODX add-on components like SPForm, Login, getResources, and FormIt
  • MODX security Permissions
  • Customizing the MODX Manager
  • Using Form Customization
  • Creating Transport Packages
  • MODX and xPDO object methods
  • MODX System Events
  • Using PHP with MODX

Go here for more information about the book.

Thank you for visiting BobsGuides.com

  —  Bob Ray