Lessons Learned about caching in MODX Revolution

So you've finally built your first MODX Revolution based website. It has some snippets, plugins, chunks, TVS and you even have site visitors. Now what? Optimize baby.

Optimization means faster load times, and happier visitors.

Site optimization is a huge umbrella of activities all leading to a better experience for your visitors. One of those activities is caching and that's what this blog is about. The takeaway for me is that it's crucial to cache everything possible to enable your your Revolution based site to work as efficiently as possible. There are tons of configurable site settings that will do a lot of the heavy lifting, but what about on a smaller level?

Enter getCache

GetCache is a Revolution snippet, developed by Jason Coward, that according to its documentation is:

A generic caching snippet for caching the output of any MODx Element using a configurable cache handler.

It's real benefit is that it allows you to cache everything.(Pssst, It doesn't mean you should).

Let's say you have a twitter feed on your site using the get feed snippet. How often do you really need to refresh the feed? Caching that with getCache will save a ton of processing. According to Jason Coward on his blog,

"It may not seem like much to cache this one Snippet call for 20 minutes, but if you are getting 100 requests per second or more, you don't want every request executing the query; it simply doesn't make sense..."

So how do we micro cache stuff with getCache?

It is easy peasy my friend. Taking my getFeed snippet call for example, I changed it from:

[[getFeed` 
&url=`http://twitter.com/statuses/user_timeline/1130xxxxx.rss` 
&tpl=`twitterFeedTpl`
&limit=`3`   
]]

to:

[[!getCache?
&element=`getFeed` 
&cacheExpires=`1800`
&url=`http://twitter.com/statuses/user_timeline/1130xxxxx.rss` 
&tpl=`twitterFeedTpl`
&limit=`3`   
]]

Notice the cacheExpires parameter. This counts the number of seconds that the snippet will stay in the cache. You can then expand this technique to chunks and snippets throughout the site according to you caching strategy.

Caching Strategy you say?

Yep that's right, you need one. You need to sit down and plan out all the items that are and are not cacheable. And then for how long. And after you come up with the strategy execute it. You can learn a lot more about this by visiting this blog article by Mark Hamstra

The results?

Faster load times, less processing, happier visitors and happier clients.

As a parting shot, I'd like to mention that this I've picked up while trying to get a single context site to load quicker. I am also NOT an expert. I'm trying to share what will hopefully save a newbie a few hours of their time

My next challenge will be learning how to cache thumbnails for the Gallery snippet.

Get the Package or through package management in the manager of your site

And please, do share your thoughts below.

Add Your Comment

Comments powered by LudwigDisqus for ModX


Get Growth

Grow your Shop's Revenues

Curious? See Past Issues

Bike Shop SEO

443 Lincoln Circle
Louisville, CO 80027
Bike Shop SEO © 2018 | Sitemap