We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3186 ☆ A M B ☆
    • 279 Posts
    Hi all,

    Just working on my first component with caching. The cache files are per visitor of the site (wich uses a certain funtionality) and when they are changing something (wich will not be often, so thats the caching for) I want to refresh the cache for that visitor only. I have this cache structure

    core/cache/mycmp/subfolder/files.cache.php


    I do this to refresh the cache, wich removes all the cache files and I want to remove only the with a specific id (wich I knows)

    $modx->getCacheManager();
    $modx->cacheManager->refresh(array('mycmp' => array('subfolder' => array())));


    Hope you understand and can help me with this

    Regards, Bert
      MODX Ambassador (NL) & Professional MODX developer
      Follow me on Twitter | Visit my page on Facebook | View my code on Github | View my script posts
      MODX e-commerce solution SimpleCart
      • 28215
      • 4,149 Posts
      $modx->cacheManager->delete('mycmp/subfolder/files');
        shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
        • 3749
        • 24,544 Posts
        Is this necessary?

        $modx->getCacheManager();
          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
          • 3186 ☆ A M B ☆
          • 279 Posts
          I had it from the tutorials so I think it is needed... not always by the way, I see that sometimes I dont do that

          @Shaun; thanks for your reply, I have looked in the cachemanager class but didnt find that, I'm gonna try that! [ed. note: bertoost last edited this post 15 years, 1 month ago.]
            MODX Ambassador (NL) & Professional MODX developer
            Follow me on Twitter | Visit my page on Facebook | View my code on Github | View my script posts
            MODX e-commerce solution SimpleCart
            • 22303 MODX Staff
            • 10,725 Posts
            Quote from: BobRay at Sep 18, 2011, 12:05 AM
            Is this necessary?

            $modx->getCacheManager();
            It really depends on where you call it, but it doesn't hurt anything and ensures that the instance is loaded if it isn't already.


            Quote from: bertoost at Sep 18, 2011, 03:26 AM

            @Shaun; thanks for your reply, I have looked in the cachemanager class but didnt find that, I'm gonna try that!
            Though that will work with the default xPDOFileCache, beware that in order to do this with other cache implementations you need to pass an option. I recommend calling this option if you intend to delete multiple keys as this is not supported natively in many caching systems and some do not provide any way to iterate keys via a path. The option is ignored by xPDOFileCache, so it does no harm to call it. Just be aware that certain cache implementations may not support this behavior or it may be more expensive than the file system implementation in terms of execution time.

            $modx->cacheManager->delete('path/to/many/things', array(
                'multiple_object_delete' => true
            ));
              • 3186 ☆ A M B ☆
              • 279 Posts
              sorry for my late reaction; I was a little bit sick so couldn't do anything...

              I use the default MODx cache method so I think the "multiple_object_delete" isn't needed.

              The delete() function doesn't do anything, the cache file path is correct (relative from the corec/cache directory, without the .cache.php file existension).
                MODX Ambassador (NL) & Professional MODX developer
                Follow me on Twitter | Visit my page on Facebook | View my code on Github | View my script posts
                MODX e-commerce solution SimpleCart
                • 3186 ☆ A M B ☆
                • 279 Posts
                I checked the delete() function a bit; and I can say that the return value is false. Wich means he cannot receive a cache-provider-oject?

                public function delete($key, $options = array()) {
                    $return= false;
                    if ($cache = $this->getCacheProvider($this->getOption(xPDO::OPT_CACHE_KEY, $options), $options)) {
                        $return= $cache->delete($key, $options);
                    }
                    return $return;
                }


                I call this function like:

                $modx->cacheManager->delete('path/to/cache/file');
                  MODX Ambassador (NL) & Professional MODX developer
                  Follow me on Twitter | Visit my page on Facebook | View my code on Github | View my script posts
                  MODX e-commerce solution SimpleCart
                  • 22303 MODX Staff
                  • 10,725 Posts
                  But the default could be configured to something that does not even support multiple object delete is my point. So you shouldn't depend on that functionality unless you are not worried about this possibility if sharing the component.

                  As for the return value of false, that just means there was no file to be deleted or it was unable to for some reason. See if you have any MODX or PHP error log entries...
                    • 3186 ☆ A M B ☆
                    • 279 Posts
                    I don't have errors in PHP or MODx error log. The component is realy custom and would not be released for the public
                      MODX Ambassador (NL) & Professional MODX developer
                      Follow me on Twitter | Visit my page on Facebook | View my code on Github | View my script posts
                      MODX e-commerce solution SimpleCart
                      • 3186 ☆ A M B ☆
                      • 279 Posts
                      For now I use the method to delete all the cache files because otherwise this isn't working correctly at all.. but hopefully you can help me with deleting a single file because there can be hundreds of them and rebuilding all will be slow down the load of the website..
                        MODX Ambassador (NL) & Professional MODX developer
                        Follow me on Twitter | Visit my page on Facebook | View my code on Github | View my script posts
                        MODX e-commerce solution SimpleCart