We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 29653
    • 9 Posts
    Brief Description
    The number of database queries is reduced by several times due to caching of dynamic snippets.


    Installation
    You should create the directory /assets/plugins/cacheaccelerator.
    In directory cacheaccelerator you should create directory cache
    (/assets/plugins/cacheaccelerator/cache).
    For both directories the chmod 777 has to be set

    Afterwards from downloaded archive you should copy the file fileCache.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. The contents of file CacheAccelerator_snippet.php should be copied there.

    The created snippet should be saved. After this you ought to go to inlay Plugins and click Create plugin. The new plugin 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 and OnSiteRefresh from the section Cache Service Events! Push the button Save. The installation of plugin is over.

    The usage of CacheAccelerator
    CacheAccelerator can be used just for all snitteps and can cache all issues. The usage of CacheAccelerator is illustrated with to examples bellow.

    The calling of Dito is the following:
    [!CacheAccelerator?
    &snippetToCache=`Ditto`
    &cacheId=`News`
    &parents=`1`
    &display=`10`
    &paginate=`1` 
    &paginateAlwaysShowLinks=`1`
    !]
    


    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.

    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.

    Example:
    &dropCacheField=`JotForm||post;true;2||;delete;2`
    


    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 from 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.

    noCacheRoles – the manager roles list for which the caching processing is not applied. E.g. `Administrator||Editor`


    Cache can be cleared from call:
    From page:
    [!CacheAccelerator? &clearCache=`1`!]
    


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


    All placeholders specified by cache snippet are also cached and are notified for calling from cache.
    Example:
    [!CacheAccelerator?&snippetToCache=`Ditto`&cacheId=`News`]]
    Showing [ start ] - [ stop ] from [ total ] News<br>
    [ previous ] [ pages ] [ next ]<br>


    If the plugin PHx is installed, the placeholders could be cut.
    In this case for page navigation usage snippet include can be applied. (http://code.google.com/p/modx-shopkeeper/downloads/detail?name=include_snippet.zip):
    [!include? &placeholder=`pages`!]
    


    If you don’t want provide cache processing for those users who are authorized in manager MODx, change snippet code:
    if($noCacheRoles)

    To
    if($noCacheRoles) 
        $nocache = isUserRole(explode("||",$noCacheRoles)) ? 2 : $nocache;
    else
        $nocache = $modx->checkSession() ? 2 : $nocache;
    


    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.

    The conditions list:
    1 != Not equal
    2 = Equal
    3 < less than
    4 > greater than
    5 <= less or equal
    6 >= greater of equal
    7 Contains
    8 Not contains
      • 4310
      • 2,310 Posts
      Very interesting smiley
      Where’s the link?
      I couldn’t find it in the repository sad
        • 29653
        • 9 Posts
        Link in repository:
        http://modx.com/extras/package/cacheaccelerator

        New versions of CacheAccelerator you may download from here:
        http://www.master-53.ru/blog/index/cacheaccelerator.-download-and-discuss.html
          • 4310
          • 2,310 Posts
          Thanks, just found it under Utilities in the Repo.
            • 4310
            • 2,310 Posts
            With 6 Ditto calls to create a fairly complex events listing with multiple document levels:
            Before - MySQL: 0.0933 s, 268 request(s), PHP: 0.1437 s, total: 0.2370 s, retrieved from database
            After - MySQL: 0.0081 s, 5 request(s), PHP: 0.0134 s, total: 0.0214 s, retrieved from cache
            Way to go, a 10 x improvement grin
            Amazing work/results, many thanks wink
              • 26931
              • 2,314 Posts
              With 6 Ditto calls to create a fairly complex events listing with multiple document levels:
              Before - MySQL: 0.0933 s, 268 request(s), PHP: 0.1437 s, total: 0.2370 s, retrieved from database
              After - MySQL: 0.0081 s, 5 request(s), PHP: 0.0134 s, total: 0.0214 s, retrieved from cache
              Way to go Grin
              Amazing work/results, many thanks Wink
              wow shocked

              thanks for sharing, thebat053!
                • 10257
                • 55 Posts
                Quote from: bunk58 at Apr 03, 2011, 05:07 AM

                With 6 Ditto calls to create a fairly complex events listing with multiple document levels:
                Before - MySQL: 0.0933 s, 268 request(s), PHP: 0.1437 s, total: 0.2370 s, retrieved from database
                After - MySQL: 0.0081 s, 5 request(s), PHP: 0.0134 s, total: 0.0214 s, retrieved from cache
                Way to go, a 10 x improvement grin
                Amazing work/results, many thanks wink

                Comparing database / cache retrieval isn’t that fair, is it? You should rather compare cache retrieval before and after applying CacheAccelerator...
                  • 29653
                  • 9 Posts
                  Quote from: fthieme at Apr 03, 2011, 07:02 AM

                  Comparing database / cache retrieval isn’t that fair, is it? You should rather compare cache retrieval before and after applying CacheAccelerator...
                  There is no MODx caching for multi-page ditto calls or jot (with post comment) calls. Nothing to compare smiley
                    • 4310
                    • 2,310 Posts
                    Yes, sorry, posted the comparison wrong data :
                    Cached page/Cached Ditto call :MySQL: 0.0084 s, 5 request(s), PHP: 0.0140 s, total: 0.0224 s, retrieved from cache
                    Uncached page/Cached Ditto call : MySQL: 0.0891 s, 268 request(s), PHP: 0.1323 s, total: 0.2215 s, retrieved from database
                    Cached page/Uncached Ditto call : MySQL: 0.0874 s, 264 request(s), PHP: 0.1266 s, total: 0.2139 s, retrieved from cache
                    Cached page/Cached CacheAccelerator call - MySQL: 0.0081 s, 5 request(s), PHP: 0.0134 s, total: 0.0214 s, retrieved from cache
                    I’m now realising I don’t understand the cache system.
                    A cached page with a cached Ditto call with another cached Ditto call inside the main Ditto tpl still works when I change some data on a child page.
                    In this scenario there is no apparent gain/benefit in using the Cache Accelerator.
                    I always alternate page/snippet/inner snippet caching, but is it necessary?
                      • 29653
                      • 9 Posts
                      Quote from: bunk58 at Apr 03, 2011, 08:11 AM

                      Cached page/Cached Ditto call :MySQL: 0.0084 s, 5 request(s), PHP: 0.0140 s, total: 0.0224 s, retrieved from cache
                      Uncached page/Cached Ditto call : MySQL: 0.0891 s, 268 request(s), PHP: 0.1323 s, total: 0.2215 s, retrieved from database
                      Cached page/Uncached Ditto call : MySQL: 0.0874 s, 264 request(s), PHP: 0.1266 s, total: 0.2139 s, retrieved from cache
                      Cached page/Cached CacheAccelerator call - MySQL: 0.0081 s, 5 request(s), PHP: 0.0134 s, total: 0.0214 s, retrieved from cache
                      The results are same but with CacheAccelerator you can use pagination. With classic cached Ditto call - not.