We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 34178
    • 212 Posts
    Quote from: BobRay at Jan 23, 2013, 11:02 PM
    (chunks, templates, and TVs are not saved in the cache as far as I can tell)

    Yes indeed. You are right. Chunks are cached within the resource as far as I see it correct.

    TVs: are not cached as far as I could see in a test

    Templates: With Template I am not sure. As far as I can see there is a bug on saving a template while having 'Clear Cache on Save' unchecked. Although 'Clear Cache on Save' is unchecked it clears the cache on saving in our installation.

    So, only selective clearing the cache of single snippets is needed anymore (another donation of course will follow smiley ).

    Thanks a lot again ...
      • 42562
      • 1,145 Posts
      Yes, true that! then MODx would truly give not only Design Freedom, but Usability Freedom. I have started keeping some of my chunks and templates (those I find myself tweaking often) outside MODx. Funny, how editing, and calling them uncached with an include script, proves a lot better experience than touching the one chunk within MODx and having all your multi-domain sites re-flippin'-freshed.

      So, only selective clearing the cache of single snippets is needed anymore (another donation of course will follow ).
      AMEN to that.
        TinymceWrapper: Complete back/frontend content solution.
        Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
        5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.
        • 3749
        • 24,544 Posts
        I've worked on it, but without much success. Snippets and plugins are stored in not one, but two places in the cache, and I don't understand the relationship between the two copies. MODX also seems to want to clear the whole site cache when you save either one, regardless of what I've tried.
          Did I help you? Buy me a beer
          Get my Book: MODX:The Official Guide
          MODX info for everyone: http://bobsguides.com/modx.html
          My MODX Extras
          Bob's Guides is now hosted at A2 MODX Hosting
          • 42562
          • 1,145 Posts
          O wow. There is some complication!

          Perhaps disabling caching for chunks/snippets altogether... would this be a good idea if possible, for certain scenarios?
            TinymceWrapper: Complete back/frontend content solution.
            Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
            5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.
            • 3749
            • 24,544 Posts
            You can always turn off the cache_scripts System Setting.
              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting
              • 34178
              • 212 Posts
              Do I understand correctly that deleting the corresponding snippet-file is not the problem but telling modx not to clear the cache when saving a snippet is the real issue?

              For clearing selectively the cache of a snippet it is probably enough to delete the file in the folder /core/cache/scripts/elements/modsnippet. Correct?
                • 42562
                • 1,145 Posts
                @BobRay Does cache_scripts affect only Snippets and Plugins? and not Templates and Chunks?

                @lettis deleting the physical files might be one good way, although it's tacky. I have not thought about that, for some reason.
                The core/cache folder has everything arranged..hmmm
                  TinymceWrapper: Complete back/frontend content solution.
                  Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
                  5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.
                  • 3749
                  • 24,544 Posts
                  @lettis There is also a copy in core/cache/includes/elements/modsnippet, and yes I think there is a problem with keeping MODX from clearing the whole site cache when you save a snippet, but I can't remember for sure. This is also the case with templates.

                  @donshakespeare Yes, cache_scripts only affects snippets and plugins. Templates aren't cached in the first place (nor are TVs).


                  Just deleting the cache file is fine unless you want to distribute your code. In that case you don't know what cache scheme is being used and you end up with something ugly and difficult to read like this:

                  $ck = $resource->getCacheKey();
                              $mgrCtx = $modx->context->get('key');
                              $cKey = str_replace($mgrCtx, $ctx, $ck);
                  
                              $modx->cacheManager->delete($cKey, array(
                                  xPDO::OPT_CACHE_KEY => $modx->getOption('cache_resource_key', null, 'resource'),
                                  xPDO::OPT_CACHE_HANDLER => $modx->getOption('cache_resource_handler', null,
                                      $modx->getOption(xPDO::OPT_CACHE_HANDLER)),
                                  xPDO::OPT_CACHE_FORMAT => (integer)$modx->getOption('cache_resource_format', null,
                                      $modx->getOption(xPDO::OPT_CACHE_FORMAT, null, xPDOCacheManager::CACHE_PHP))
                                  )
                              );
                              /* see if resource exists in any other contexts, and if so, clear those caches too */
                              $ctxResources = $modx->getCollection('modContextResource', array('resource' => $docId));
                  
                              foreach ($ctxResources as $ctxResource) {
                                  /* @var $ctxResource modContextResource */
                                  $key = $ctxResource->get('context_key');
                                  $cKey = str_replace($mgrCtx, $key, $ck);
                                  $modx->cacheManager->delete($cKey, array(
                                      xPDO::OPT_CACHE_KEY => $modx->getOption('cache_resource_key', null, 'resource'),
                                      xPDO::OPT_CACHE_HANDLER => $modx->getOption('cache_resource_handler', null,
                                          $modx->getOption(xPDO::OPT_CACHE_HANDLER)),
                                      xPDO::OPT_CACHE_FORMAT => (integer)$modx->getOption('cache_resource_format', null,
                                          $modx->getOption(xPDO::OPT_CACHE_FORMAT, null, xPDOCacheManager::CACHE_PHP))
                                     )
                                  );
                  
                              }


                  An $object->clearCache() convenience method would come in really handy. I think I'll put in a feature request. wink
                    Did I help you? Buy me a beer
                    Get my Book: MODX:The Official Guide
                    MODX info for everyone: http://bobsguides.com/modx.html
                    My MODX Extras
                    Bob's Guides is now hosted at A2 MODX Hosting
                    • 34178
                    • 212 Posts
                    Quote from: BobRay at Mar 01, 2013, 02:57 AM
                    An $object->clearCache() convenience method would come in really handy. I think I'll put in a feature request. wink

                    Maybe let´s ask the modx-core-developers directly what they recommend which way should be followed to improve this very important point of selective cache clearing of single snippets?
                      • 3749
                      • 24,544 Posts
                      I've submitted a feature request. If it goes through, the recommended methods will be inside the convenience function. This will be handy if the cache system changes (as it has before).
                        Did I help you? Buy me a beer
                        Get my Book: MODX:The Official Guide
                        MODX info for everyone: http://bobsguides.com/modx.html
                        My MODX Extras
                        Bob's Guides is now hosted at A2 MODX Hosting