CacheAccelerator 0.2-alpha

CacheAccelerator 0.2-alpha

Released Mar 08, 2011 by thebat053
The number of database queries is reduced by several times due to caching of dynamic snippets. Like Ditto, Jot and e.t.c. Download 8kb (428 downloads)
Downloads: 428
License: GPLv2
Requires Evolution 1.0.x or greater
Compatible up to Evolution 1.0.x
Alpha version, but working.

Installation Instructions

The number of database queries is reduced by several times due to caching of dynamic snippets.

The snippet code:

<?phpreturn require MODX_BASE_PATH.'assets/plugins/cacheaccelerator/CacheAccelerator_snippet.php';?>

The parameters:

snippetToCache – the snippets name for caching. E. g. ‘Ditto’.cacheId – the cached snipped  identifier inside the page. E. g. ‘News’.dropCacheField – the list of fields and conditions for them, by which the cache is reset. E. g.  `JotForm||post;true;2`noCacheGroups – the list of web-users groups for which the caching is not applied.  E.g. `admins||moderators`noCacheRoles – the manager roles list for which the caching processing is not applied. E.g. `Administrator||Editor`checkURL
– create separate cache for different URL (1|0). Is enabled  by
default. It is recommended to enable it for snippets that use the page
navigation. clearCache – setting it to 1 leads to forced cache clearing.

(!) If the plug-in PHx is installed, the placeholders could be cut.In this case for page navigation usage snippet “include” can be applied. (

[!include? &placeholder=`pages`!]


You should create the directory  


In directory cacheaccelerator you should create directory cache (/assets/plugins/cacheaccelerator/cache).

For both directories the chmod 777 has to be setAfterwards from downloaded archive you should copy the files fileCache.php and CacheAccelerator_snippet.php to the directory /assets/plugins/cacheaccelerator

After that in the manager MODx choose Elements -> Elements management -> Snippets -> New Snippet. Create a new snippet called CacheAccelerator.

<?phpreturn require MODX_BASE_PATH.'assets/plugins/cacheaccelerator/CacheAccelerator_snippet.php';?>

This contents should be copied there. The created snippet should be saved.

After this you ought to go to inlay “Plug-ins” and click “Create plug-in”. The new plug-in should be called CacheAcceleratorClear. Copy the contents of file CacheAcceleratorClear.plugin.txt. 

Attention! After copying the plug-in contents go to inlay “System events”, where you should set the check button for event OnCacheUpdate from the section  Cache Service Events! Push the button “Save”. The installation of plug-in is over.

The usage of CacheAccelerator:

CacheAccelerator can be used just for all plug-ins and can cache all
issues. The usage of this plug-in is illustrated with to examples

The calling of Dito is the following:

Instead of calling “Ditto” the snippet CacheAccelerator is called. The name of cashed snippet (in this case “Ditto”) is specified in parameter snippetToCache.Next, there is cacheId
parameter. Its purpose is to divide the cashed content when there are
several cashed snippets per one page. For example, the left menu, the
last news block and rolling news. It can have any value that is correct
for cached content. Note, if Ditto is called with double square
brackets, this calling should be the same.

Example of Jot calling:

[!CacheAccelerator?&snippetToCache=`Jot`&cacheId=`Comments`&dropCacheField=`JotForm||post;true;2||;publish;2||;unpublish;2||;delete;2||;edit;2`&noCacheGroups=`Site Admins`&customfields=`name,email`&pagination=`10`&badwords=`*****`&canmoderate=`Site Admins`&captcha=`1`!]]]

The cached snippet is also specified in parameter snippetToCache. Parameter cacheid specifies the identifier of cashed content on given page. Here are also two more parameters dropCacheField and noCacheGroups.
Let’s regard them more detailed. News blocks and comments rolling
differ from each other. News blocks are added with manager MODx and
addition of any news item leads to cache clearing, while comments
rolling let any user to create post. But in order make this post be
available for other users, the cache CacheAccelerator has to be cleared.
This activity may be necessary not only for Jot, but also for all other
snippets, which are desired to be cached, but also this cache should be
updated after concrete users actions. This aim is achieved with
parameter dropCacheField. It includes the list of
conditions for cache CacheAccelerator. The field name can be used as
condition. If this name is detected in GET or POST queries, the cache will be updated.
This condition can be also a comparison. You should enumerate field,
value, the comparison method divided from each other with semicolumn. If
the field name is empty, all existed fields are exposed to comparison.



Here is specified the following:

  • If query includes field JotForm
  • If field post exist and its value is true
  • If any of fields has value delete

If any of these conditions is true, the cache will be cleared.

When any new message is posted to Jot, a new form is transmitted. This form contains field JotForm.
So after posting such message the cache will be cleared and information
is kept to be timely. After the first query of this page cache will be
created again and all other following queries will be processed with
help of cache.Parameter noCacheGroups contains the
list which is divided with ||. This list consists of users groups. For
these users the data are got from cache and snippet is executed each
time when call occurred. As instance, let’s regard the moderator forms.
This form and web-user form are different. Moderator form has control
buttons unlike user form. But If this form is stored in cache, all other
users will be able to get moderator form which doesn’t correspond to
there queries. By default cache processing is not provided for those users who are authorized in manager MODx(!). And if your editor is the user of administration panel, this problem is overcome.

You must logout from administration panel for test cacheAccelerator call.


Cache can be cleared from call:
From  code fragment:

[!CacheAccelerator? &clearCache=`1`!]

From sippet:

$modx->runSnippet("CacheAccelerator", array("clearCache" => 1))

All placeholders specified by cache snippet are also cached and are notified for calling from cache.


Showing [ start ] - [ stop ] from [ total ] News<br>[ previous ] [ pages ] [ next ]<br>

The conditions list:

1 != Not equal2 = Equal3 < less than 4 > greater than5 <= less or equal6 >= greater of equal7 Contains8 Not contains