We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 2690
    • 148 Posts
    Hey all!

    I’m still working on the multi-server setup for modx installation. Couple more questions:

    1. How often does the site cache gets renewed?

    2. What triggers the cache to be cleared (i’m not talking about the admin button ’clear cache’)? For example if i have a static page and it has the cached copy and than i do some modifications to the page and republish - will it trigger the clearing of the cache?

    3. if i have 3 identical copies of MODx on 3 different servers (under load balancer) - should i worry about the cache? (or just allow each server to create its own set of cached pages? - i guess the answer to the 1st question will make a big difference in this case smiley )


    Once i’m done with the setup i’ll try to share the steps with all for future references.
    Thank you for all your help guys!

    Aleks
      MODx Revo 2.0.6-pl (Traditional) | Apache 2.2.3 | PHP 5.2.14 | MySQL 5.0.77 | MAC OS 10.6.5 | FF 3.6/Chrome 9.0.5
      • 22303 MODX Staff
      • 10,725 Posts
      Quote from: bakalek at Feb 21, 2008, 11:14 AM

      1. How often does the site cache gets renewed?
      Every time you edit a document or MODx resource, the site cache file is recreated.

      Quote from: bakalek at Feb 21, 2008, 11:14 AM

      2. What triggers the cache to be cleared (i’m not talking about the admin button ’clear cache’)? For example if i have a static page and it has the cached copy and than i do some modifications to the page and republish - will it trigger the clearing of the cache?
      Yep, unless you uncheck the clear cache option when saving the document. This will defer the rebuilding of the cache until you manually do it or save again without unchecking it.

      Quote from: bakalek at Feb 21, 2008, 11:14 AM

      3. if i have 3 identical copies of MODx on 3 different servers (under load balancer) - should i worry about the cache? (or just allow each server to create its own set of cached pages? - i guess the answer to the 1st question will make a big difference in this case smiley )
      You would have to have a shared file system for the PHP sessions, otherwise, MODx will not work with load balancing anyway. I guess the cache files could be left to each instance though, if you can get a common file system location mounted to each web server.

      The 0.9.7 series will overcome this limitation by providing a default session implementation that uses the database instead of PHP’s default session handling which relies on the file system.
        • 2690
        • 148 Posts
        The 0.9.7 series will overcome this limitation by providing a default session implementation that uses the database instead of PHP’s default session handling which relies on the file system.
        will it decrease MySQL performance a bit?

        Every time you edit a document or MODx resource, the site cache file is recreated.
        So we can probably develop a plugin that will run on ’OnDocPublished’ and trigger a notification script for other servers to delete the cache for that particular document id.
          MODx Revo 2.0.6-pl (Traditional) | Apache 2.2.3 | PHP 5.2.14 | MySQL 5.0.77 | MAC OS 10.6.5 | FF 3.6/Chrome 9.0.5
          • 2690
          • 148 Posts
          You would have to have a shared file system for the PHP sessions, otherwise, MODx will not work with load balancing anyway. I guess the cache files could be left to each instance though, if you can get a common file system location mounted to each web server.

          The 0.9.7 series will overcome this limitation by providing a default session implementation that uses the database instead of PHP’s default session handling which relies on the file system.
          What if we keep the user state on one machine through the load balancer? For example user 1 connected and load balancer pointed him to server 3, and for all future user activity (during the session) the LB keeps him on one server - 3? this should work, no ?
            MODx Revo 2.0.6-pl (Traditional) | Apache 2.2.3 | PHP 5.2.14 | MySQL 5.0.77 | MAC OS 10.6.5 | FF 3.6/Chrome 9.0.5
            • 7914
            • 137 Posts
            I realize this is an old post, but my question fits best here.

            I am running a similar setup. (2 servers fed through a load balancer).

            I understand what is being asked about session persistence. Here is a scenario that I would like further clarification on simply because...well I don’t know how it works. smiley

            lets say I log into my site, the LB sends me to my first server. I make some changes and clear out the site cache. Is it safe to assume that only my first server has the site cache cleared? So, I would need to (somehow) get logged into my site from my second server and clear the cache there as well?

            Thank you for your time!
              • 22303 MODX Staff
              • 10,725 Posts
              For MODX Revolution, sessions are stored in the database, so it is load balancer ready. For MODX Evolution, you will need to handle this using "sticky" sessions or providing a custom session handler at the PHP level.
                • 7914
                • 137 Posts
                Ok, that makes sense, but let me ask you this.

                Lets say I am on server 1, I make a change and the page is cached. The physical cache file is going to live on server 1 correct? So, if I clear the site cache, I will clear the physical files on whichever server I happen to land on.

                I am noticing on my site that once I make a change, sometimes I see the change - other times I do not. If I clear out the cache (so a new file gets written) I understand it now that this process only happens on whichever server I am currently on. The other server will still have the older cached file.

                I am probably getting myself confused, and I apologize for beating this into the ground. I really appreciate your time.
                  • 22303 MODX Staff
                  • 10,725 Posts
                  Quote from: dowhatnow at May 02, 2011, 12:27 PM

                  Lets say I am on server 1, I make a change and the page is cached. The physical cache file is going to live on server 1 correct? So, if I clear the site cache, I will clear the physical files on whichever server I happen to land on.
                  That’s a great question actually. We have dealt with this using a couple of plugins...

                  The first, which I attach to OnWebPageComplete, registers each server instance for 20 minutes (this was designed for a cloud deployment that would launch and kill new server instances on demand, but you can remove the expiration time to avoid the overhead of writing those messages every 20 minutes) and then looks for any messages with the command ’clearCache’ specified. The second, attached to the OnSiteRefresh event allows clearing the cache in the manager to register a ’clearCache’ message with all of the remote server ’instances’ that have been registered by the first plugin. You can take the idea and tailor it for your environment, but in our experience the best practice is to isolate one server instance for the manager (via subdomain configuration or similar) that is separate from your remote web nodes. This allows activity to take place on the manager instance in high volume, then changes only get pushed out when the Refresh site action is taken from the Admin menu.

                  You could also configure the cache to expire at regular intervals instead.

                  Here is an example remotecommands plugin (NOTE this is for MODX 2.1, and 2.0 would be slightly different, using clearCache() instead of refresh()):
                  <?php
                  /* RemoteCommands plugin -- register with OnWebPageComplete event */
                  
                  /* find any remote commands to execute from the master instance */
                  $instance = $_SERVER['SERVER_ADDR'];
                  if (!empty($instance) && $modx->getService('registry', 'registry.modRegistry')) {
                      $modx->registry->addRegister('remotes', 'registry.modDbRegister', array('directory' => 'remotes'));
                      $modx->registry->remotes->connect();
                  
                      /* register this instance */
                      $modx->registry->remotes->subscribe("/distrib/instances/");
                      $modx->registry->remotes->send("/distrib/instances/", array($instance => true), array('expires' => time() + 1440));
                  
                      /* find any valid command messages for this instance and act on them */
                      $modx->registry->remotes->subscribe("/distrib/commands/{$instance}/");
                      $commands = $modx->registry->remotes->read(array('poll_limit' => 1, 'msg_limit' => 1));
                      if (!empty($commands)) {
                          $command = reset($commands);
                          if (!empty($command)) {
                               switch ($command) {
                                   case 'clearCache':
                                      $results= $modx->cacheManager->refresh();
                                      break;
                                   default:
                                      break;
                               }
                          }
                      }
                  }
                  ?>


                  And here is an example sendclearcache plugin for registering a remote command message to each remote server instance:
                  <?php
                  /* SendClearCache plugin -- register with OnSiteRefresh event */
                  
                  /* read instances and write clear cache msg to each command directory */
                  if ($modx->getService('registry', 'registry.modRegistry')) {
                      $modx->registry->addRegister('remotes', 'registry.modDbRegister', array('directory' => 'remotes'));
                      $modx->registry->remotes->connect();
                      $modx->registry->remotes->subscribe('/distrib/instances/');
                      $instances = $modx->registry->remotes->read(array('poll_limit' => 1, 'msg_limit' => 25, 'remove_read' => false));
                      if (!empty($instances)) {
                          foreach ($instances as $instance) {
                              if ($instance == $_SERVER['SERVER_ADDR']) continue;
                              $modx->registry->remotes->subscribe("/distrib/commands/{$instance}/");
                              $modx->registry->remotes->send("/distrib/commands/{$instance}/", 'clearCache', array('expires' => time() + 1440));
                          }
                      }
                  }
                  ?>

                    • 7914
                    • 137 Posts
                    Thank you for your detailed response! I need to read this 40 or 50 more times I think. I’m sure I will have more questions, but again - thank you for your time!
                      • 36609
                      • 1 Posts

                      Hi guys,

                      This is an interesting post for me.
                      I'm trying to do something similar, and really like the Registry approach to feeding out commands to the nodes.

                      The problem I'm having is with the Registry itself, and creating messages.
                      I've had a good look around on Google but am having trouble finding any helpful documents on using the Registry.

                      Could you point me in the direction of any docs that will help me understand the Registry better please?

                      Thanks
                      Danny