We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28042 ☆ A M B ☆
    • 24,524 Posts
    It has seemed to me for some time now that it should be possible to have multiple cache files for each resource.

    For example, when using template-switching. Or when using MIGxML for multiple languages.

    This could require each resource to have its own directory (core/cache/resources/1/, core/cache/resources/2/, etc), or a file naming convention.

    Of course, one could go crazy with the idea, a cached page for user + language + template...

    Anyway, I was thinking, base the cache filename on a value, such as "3.t2.cache.php" for resource #3, where template #2 was used. A plugin would get the $_GET['t'] value, validate it, then pull up the appropriate cached file. Cache files would be saved in the same manner; build the file name from the validated $_GET['t'] value. A default would have to be established; perhaps set in a System Setting or a plugin property, with the system's site default template as an ultimate default.
      Studying MODX in the desert - http://sottwell.com
      Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
      Join the Slack Community - http://modx.org
      • 4172
      • 5,888 Posts
      migxMulitLang, for example is using (a bit modified verson of) getCache as the template-wrapper-snippet for caching one version for each cultureKey:

      https://github.com/Bruno17/migxmultilang/blob/master/core/components/migxmultilang/elements/snippets/mmlcache.snippet.php

      It does build the cacheElementKey on basis of scriptPropertries and request-params.

      simplyfied:
          
          $scriptProperties['mml_cultureKey'] = $modx->getOption('mml_cultureKey', $scriptProperties,$modx->getOption('cultureKey'));
          $properties = $scriptProperties;
      
      
          $cacheElementKey = $modx->resource->getCacheKey() . '/' . md5($modx->toJSON($properties) .  $modx->toJSON($modx->request->getParameters()));
      
      
      
          $modx->cacheManager->set($cacheElementKey, $cached, $cacheExpires, $cacheOptions);
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        I was wondering about that! As usual, you're way ahead of me wink
          Studying MODX in the desert - http://sottwell.com
          Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
          Join the Slack Community - http://modx.org