We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 1628
    • 17 Posts
    I am trying to create a custom cache file that will not be deleted during the general clear cache call. This file will contain information on a large group resources that only needs to be updated if one of those resources is updated. I cannot find how to give the file a unique extension (something other than .cache.php) to avoid deletion. Has anyone done this before? Is there a better way to go about it?
      • 22303 MODX Staff
      • 10,725 Posts
      You can use a custom cache provider, just make sure it is not placing it’s files in the existing folder structures if you use the default xPDOFileCache implementation. FWIW, in 2.1, the folder structures are protected for each provider instance—one of many caching improvements coming soon.
      <?php
      // get the custom provider instance
      $myCache = $modx->cacheManager->getCacheProvider('myCache');
      
      // cache a value
      $myCache->set('key', $value);
      
      // get a value from the cache
      $value = $myCache->get('key');
      

        • 1628
        • 17 Posts
        Thanks for the quick response! I have looked for documentation on specifying a custom directory to save the cache in, but I haven’t found where this directory should be specified. Should it appear as a ’path’ key in an $options array in the getCacheProvider call? Also, with a custom cache provider, is there any type of initiation that needs to be setup prior to calling it? If so, is this where I specify the custom directory? If not, what’s the advantage of the custom provider other than organization?
          • 1628
          • 17 Posts
          Disregard my reply above. Now I see what you are referring to when you mention a custom cache provider, though I am still confused about setting a custom path/directory.
            • 22303 MODX Staff
            • 10,725 Posts
            You can set a custom cache_path (to override the regular cache path pointing to core/cache/), cache_ext (.cache.php by default), and/or cache_prefix in the options array when calling getCacheProvider(), e.g.
            <?php
            // get the custom provider instance
            $myCache = $modx->cacheManager->getCacheProvider('myCache', array(
                'cache_ext' => '.mycache.php',
                'cache_path' => '/var/tmp/mycache/',
                'cache_prefix' => 'some/path/and/or/key_prefix_'
            ));
            

              • 1628
              • 17 Posts
              Great, thanks again.