MODX Quick Tip: microcache

Jul 5, 2013

The Problem

In the most common PHP + web server configuration, responses are sent with no-cache headers, because oftentimes PHP applications serve dynamic content. This usually works out - we don't want users getting stale content, or worse, private content of other users.

The problem is that sometimes, MODX (a PHP application) serves content that doesn't change all that often - "quasi-static" content if you will. Occasionally, MODX serves up content that is categorically static in nature and should be cached in-browser. One example is when you use one of the static Resource content types.

The Solution

Enter microcache. This as-yet-unknown plugin is another work of art by MODX Lead Architect Jason Coward. All you have to do is install it via Package Management*, and by default it sets public cache control headers on cacheable Resources requested by anonymous users.

There's a lot of intelligence here. I highly suggest you read the documentation here, but to summarize: it knows when a Resource should be cached in-browser and sends the correct headers to enable it.

Just another piece of awesomeness from the folks who brought you MODX :P

*P.S. There is one tiny glitch atm: you need to manually set the Plugin to listen to the OnWebPagePrerender event. You do this by clicking the Plugin's name in the Elements tree, go to the "System Events" tab, scroll to the very bottom, enable the OnWebPagePrerender event, and save. The bug is filed here, FYI.