We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 22295
    • 153 Posts
    I have various different views of the same data (a user, in this example). currently, I use this, but i’m in the beginning of the code revision related with cache - so it can change.

    		// CUSTOM CACHE READ
    		$cacheDir = 'custom/very/custom/';
    		$cachedResult = $this->modx->cacheManager->get($cacheDir.$userId);
    		if (!empty($cachedResult)) return $cachedResult;
    
    		$result = array();
    .
    .
    all the code
    .
    .
    
    		// CUSTOM CACHE WRITE
    		$this->modx->cacheManager->writeTree($cacheDir);
    		$this->modx->cacheManager->set($cacheDir.$userId,$result);
    		return $result;




    1. clearCache - clearing multiple files related with an id (user, for example)
    a. could is recurse folders to remove all (id) ’3.cache.php’ ?
    (otherwise, store in single folder)
    b. could it remove from single folder by wildcard? ’3_*.cache.php’

    otherwise - i’d do a class to manage these custom folders list, and a function to recurse through them. what is the recommended approach to this?

    2. (future-proof) which method would be "memcached-ready"?


    thanks in advance
      • 22295
      • 153 Posts
      (Question #1)
      Looking at modCacheManager class (line 445), i see the answer to question (1) is - ’no, well kind of..’. It can clear a folder (and decedents) and specific file(s).
      This is not an issue - as anyway I’ll use my own clearCache function. deleteTree function has delete_exclude_patterns, so regex can help : ’/^((?!’.$cacheKey.’).)*$/’

      The only thing that would be ’nice to have’ is that the site-wide clear-cache (via manager) would read also a setting to clearCache - custom cache paths (without modding \core\model\modx\processors\system\clearcache.php :18)
      I understand this could be resolved via a Plugin on OnCacheUpdate event, but I prefer not to (as /manager-clear_cache is really a misc function in my setup and -
      "Any plugins registered to your events would be loaded into the context cache of every context in the system" - OpenGeek
      http://modxcms.com/forums/index.php/topic,43595.msg260255.html#msg260255

      more generic - would be nice if a (custom) class construct could register it’s cache-path for this purpose. Adding caching to any add-on, for example getResources’s rendered views (by tpl) would be a quite simple - as most modx setups use the manager interface - clearing the entire cache on each action (by default).



      (Question #2)
      ’yes’ - I see: xpdomemcache.class.php, well done - mr. generic smiley
      Also, I see the way it’s implemented in modCacheManager->clearCache : first [’objects’] delete from whatever cache handler, then [’path’] optionally removes from file-system.
      Then - digging in xpdocachemanager.class.php, I just wanna say: jason, great stuff!

      thanks.