We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 2921
    • 11 Posts
    Here’s the situation:
    Within MODx, I’m retrieving a file list from a remote server using SOAP.
    I want the retrieved data (a simple array) to be cached. My initial plan was to use the PEAR::Cache_Lite class, but this throws a MODx parse error in my face sad (This has to do with a failing @fopen on a missed cache event, see also the topics http://modxcms.com/forums/index.php/topic,4340.0.html and http://modxcms.com/forums/index.php/topic,4306.0.html)

    I really would like to use the PEAR::Cache_Lite classes, but as an alternative, would it be possible to use the MODx caching system to cache your own data (an array in my case).

      • 21255
      • 215 Posts
      I guess you could create your array within the documentObject, say
      $modx->documentObject[’myarray’] = array(’A’ => 1, ’B’ => 2);
      Since the documentObject gets cached and rebuild from cache your data would be restored, too. Not tested at all. ;-)
      See document.parser.class.inc.php for details.
        • 2921
        • 11 Posts
        Quote from: netnoise at May 12, 2006, 11:42 AM

        I guess you could create your array within the documentObject, say
        $modx->documentObject[’myarray’] = array(’A’ => 1, ’B’ => 2);
        Since the documentObject gets cached and rebuild from cache your data would be restored, too. Not tested at all. ;-)
        See document.parser.class.inc.php for details.

        Thanks! This works like a charm!
        My code:
        if (!isset($modx->documentObject["albumcache_".$directory])) {
            // This include fills $pic_list by using SOAP
            include APP_ROOT."include/getRemoteAlbum.php";
            $modx->documentObject["albumcache_".$directory]=$pic_list;
        } else {
            $pic_list=$modx->documentObject["albumcache_".$directory];
        }
        
        // This include file show webalbum by using the contents of $pic_list
        include_once APP_ROOT."webAlbum.php";
        
        return $return_value;