We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 24351
    • 15 Posts
    Hi Guys.

    I have a CMP that updates some resources. When I update the resource from the CMP, it doesn’t clear the cache.

    When I use the regular resourec saving function and the clear cache checkbox is selected, it clears the cache...

    $p = $modx->getObject('Productdesc',1);
    
    if($p) {
    	$p->fromArray(array(
    		'name' => $strProdName,
    		'alias' => $strProdName,
    		'description' => $strProdDesc,
    	));
    
    	if($p->save()==false) {
    		echo genMessage("errormsg", $modx->errorCode());
    	} else {
    	$p->clearCache();
    	
    	}
    }
    


    I am looking for the clearCache() function... does it exists? kinda must....

    Thanks for helping me out

    Cheers Ragnar
      • 24351
      • 15 Posts
      sorry guys for reposting, but I just think that someone must know the answer to my question. Or did I post it in the wrong branch?

      Any suggestions to investigate it my self would be appreciated...
        • 11076
        • 159 Posts
        i really don’t know how to.. but here’s a discussion on selective cache clearance that might be interesting for you
        http://modxcms.com/forums/index.php/topic,59179.0.html
          Michael Shraibman( gOmp)  | Freelance Design & Development | wink  impossible is nothing...
          • 24351
          • 15 Posts
          Thanks for the hint.

          I tried to find the file that gets executed when I click the "save" button on a resource after altering it.
          but I didn’t find it.

          If I would find that function I might be able to reverse engineer the cache clearing function on on resource...

          any help still much appreciated
            • 3749
            • 24,544 Posts
            I believe it would be in these two files:

            core/model/modx/processors/resource/create.php
            core/model/modx/processors/resource/update.php

            The cache file for a particular resource in the web context would normally be:

            core/cache/web/resources/#.cache.php

            Where # is the ID of the resource, so a plugin could delete that file, but I’m not sure what the side-effects might be.
              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
              • 24351
              • 15 Posts
              thanks for the hint. I found a solution to my problem.

              So checking out the update.php file, there is a empty cache section...

              so if you are working with CMP and you are saving / updateing resources with your individual code. then you can do this to empty the cache of an updated resource.

              $resource = $modx->getObject('modResource', $yourResourceID);
              $resource->set('pagetitle', $strNewPagetitle);
              $resource->set('alias', $strNewAlias);
              if($resource->save()) {
              	/* empty cache */
              	$cacheManager= $modx->getCacheManager();
              	$cacheManager->clearCache(array (
              			"{$resource->context_key}/resources/",
              			"{$resource->context_key}/context.cache.php",
              		),
              		array(
              			'objects' => array('modResource', 'modContext', 'modTemplateVarResource'),
              			'publishing' => true
              		)
              	);
              }
              


              Thanks for helping me out here. smiley
              cheers ragnar
                • 3749
                • 24,544 Posts
                You can also just call the resource/update processor and let it do the work for you.
                  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