We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 34178
    • 212 Posts
    What about a shortcut to clear just the cache of the saved resource or a second save-button which clears only the cache of the saved page?

    We often just correct single words of the content of a webpage, like changing 'new' into 'old' what never needs to clear the whole MODx-cache. For this purpose it would be enough to clear this certain page which will not affect any other page especially not the wayfinder-snippet which took in one of our websites 2-3 seconds to load uncached because of having more the 1.000 webpages and 3 menu-levels.

    Does anybody know how to setup new shortcuts in the MODx-Backend?

    Letti
      • 34178
      • 212 Posts
      Hi Jason,
      do you know if it is intended to add a function in modx for saving without clearing the complete MODx-Cache?

      Or do you have any idea how to add an action which would save the current resource and clear only the page to be saved?

      Unfortunately when working on our site all the time the whole cash including > 1.000 pages is cleared although we make only very little changes on the pages.

      Letti
        • 38121
        • 36 Posts
        What about adding a 'regenerate cache' menu? Instead of waiting for the cache to be regenerated by users it could be be regenerated by the server. The cache regeneration could be based on different metrics such as depth of the page in the hierarchy, freshness, hits, etc., to limit server resource usage.

        Another approach is incremenal updates of the cache. A bit like git. The cache start from a state, and is modified incrementally as resources are updated. So it's never cleared, only adjusted. Users would still face a first visit load time but would be saved the time it takes to regenerate the cache. If the sate is lost or the cache is corrupt it would be cleared.

        Writing from my iPhone. I hope there's not too many typos.
          • 38121
          • 36 Posts
          forget about the incremental stuff just realized it's what being discussed. Can't edit my previous post from the iPhone.
            • 34178
            • 212 Posts
            In my opinion it is urgently needed a keyboard-shortcut to save a page which will only clear the cache of the saved page and no other page or anything else.

            There are so many editors who work on big projects and only type in words and nothing else. And if these correction affect no other pages by getresourcefield, wayfinder etc. such a keyboard-shortcut will be the best solution for this problem.

            Does anybody know how the php- or xpdo-code has to look like for saving the present resource and clearing only the cache of this page?

            For the time step this could be started by an manager-action. Later on we could assign a shortcut to this action ...

            What do others think about this?

            Letti [ed. note: lettis last edited this post 12 years, 1 month ago.]
              • 12066
              • 48 Posts
              Hi letti,

              I ended up with this little plugin, which hooks into these system events:

              • OnDocFormSave
              • OnDocFormDelete
              • OnDocPublished
              • OnDocUnPublished
              • OnEmptyTrash

              /**
               * getParents
               * Function to get the parent ID's of a resource
               * modX getParentIds() not working because there's no map for this resource ready
               */
              if($modx->event->name != 'OnEmptyTrash') {
               $par = array();
               function getParents($res) {
                global $par;
                $parent = $res->getOne('Parent');
                if($parent->get('parent') > 0) {
                  $par[] = $parent->get('id');
                  getParents($parent);
                } else {
                  $par[] = $parent->get('id');
                  return $par;
                }
                return $par;
               }
              
               // Path to the resource cache
               $resourcesPath = $modx->getOption('core_path') . 'cache/resource/web/resources/';
              
               // Store parents + home in array
               $parents = getParents($res);
               $parents[]  = 1;
              
               // Iterate through parents and remove cache resources
               foreach($parents as $parent) {
                $parentPath = $resourcesPath . $parent . '/';
                if(file_exists($parentPath) && $modx->cacheManager->deleteTree($parentPath, array('deleteTop' => true)))
                  $modx->log(modX::LOG_LEVEL_ERROR, 'JUST REMOVED ' . $parentPath);
               }


              It clears the parent resources of a resource + resource id 1 (home)
              I'm still having some tiny issues with it, so I can't assure you it's working as perfectly well.

              Probably give it a try and if you fix some stuff or extend the functionality please let me know.
              • Please note deleteTree() is a file system function and has no effect if you use other cache provider implementations. It is not intended for use in directly manipulating cache files.
                  • 12066
                  • 48 Posts
                  Hi opengeek,

                  thanks for pointing this out. It's just some kind of quick fix solving issues with rebuilding the cache on ~40000 resources strong environment + a lot of custom default cache which gets pretty huge as well and clearing always creates a huge load.

                  Is there any way to approach this issue you would suggest/recommend?

                  Thanks for any advice.
                    • 34178
                    • 212 Posts
                    @opengeek

                    If I remember correctly you mentioned long time ago you were working on a professional cache-clearing-function in a more granulated way.

                    Is there anything intended by the modx-core-team for the next future? If yes probably it makes no sense to built such a function by us 'modx-laypersons'.

                    BTW: If it helps to push a more extended clear-cache-function in modx I would like to give another donation for the modx-project. In my eyes such a cache-clearing-tool is one of the last really missing things in modx making modx also suitable for huge professional projects ...

                    Thanks a lot again for this great cms ...

                    Letti
                      • 34178
                      • 212 Posts
                      Does maybe anybody else know when the MODx-Team will improve the cache-function?

                      Or does anybody know how to implement a plugin which provides a clear cache of only the content and TVs and not everything else? Combining such a tool with removing the hook clear cash on save would maybe a very good solution.

                      Letti