opengeek
This is my new GitHub Pages Site...
About
I'm the Chief Architect of the MODX Content Management System (@modxcms) and you can contact me via GitHub (@opengeek).
I like code:
Below are some example usages of the getCache Snippet. Note that you always want to call the getCache snippet uncached, i.e. with the ! token after the opening tags...
Basic Example
The simplest example simply caches the output of the Element it is processing, using the default properties. Because the default cacheElementKey
is constructed dynamically by creating a hash of the current Resource id, the properties passed to the Element, and any parameters sent in the REQUEST, any requests with a unique parameter in the URL or dynamic property values passed to the Element will cache results separately. It also uses the resource
cache partition by default, which is cleared anytime a Resource or Element is edited in the MODX manager, or Site --> Clear Cache is called:
[[!getCache? &element=`getResources` &parents=`0` &depth=`2`]]
Custom Cache Expiration
This example is the same as the Basic Example, but expires the cache item after it has lived in the cache for 1440 seconds:
[[!getCache? &element=`getResources` &cacheExpires=`1440` &parents=`0` &depth=`2`]]
Sharing Cached Elements Across Resources
By providing a cacheElementKey
, you can specify the key used to store an item in the cache. This allows you to share the cache across Resources, so that the first Resource to be called will cache the output for all other getCache calls using that cacheElementKey
to share:
[[!getCache? &element=`getResources` &cacheElementKey=`shared_navigation` &parents=`0` &depth=`2`]]
Custom Cache Partitions
By providing a cacheKey
, you can specify a custom cache partition to store the cached Element in. This allows the cached items to survive MODX cache refreshes that occur during publishing activity:
[[!getCache? &element=`getResources` &cacheKey=`global_cache` &parents=`0` &depth=`2`]]
NOTE: The caveat with using a custom partition is that it must be expired using the cacheExpires
property (or configuring the partition with an expires option), or manually. getCache provides a processor for refreshing custom cache partitions using PHP API calls or using JavaScript via the provided connector.