/** * A method to test the saving, reading and clearing of cache data. */ function testCacheMethods() { $aConf = $GLOBALS['_MAX']['CONF']; // Test reading when no data cached $result = MAX_Plugin::getCacheForPluginById('foo', 'Maintenance', 'Fake'); $this->assertFalse($result); // Test a simple write and read $aData = array('foo', 'bar'); $result = MAX_Plugin::saveCacheForPlugin($aData, 'foo', 'Maintenance', 'Fake'); $this->assertTrue($result); $result = MAX_Plugin::getCacheForPluginById('foo', 'Maintenance', 'Fake'); $this->assertTrue(is_array($result)); $this->assertEqual(count($result), 2); $this->assertEqual($result[0], 'foo'); $this->assertEqual($result[1], 'bar'); // Test a write and read when cache data has exipired, and the validity is tested $aOptions = MAX_Plugin::prepareCacheOptions('Maintenance', 'Fake', null, 0); $result = MAX_Plugin::saveCacheForPlugin($aData, 'foo', 'Maintenance', 'Fake', null, $aOptions); $this->assertTrue($result); $result = MAX_Plugin::getCacheForPluginById('foo', 'Maintenance', 'Fake', null, false, $aOptions); $this->assertFalse($result); // Re-test the read, not checking the validity $result = MAX_Plugin::getCacheForPluginById('foo', 'Maintenance', 'Fake', null, true, $aOptions); $this->assertTrue(is_array($result)); $this->assertEqual(count($result), 2); $this->assertEqual($result[0], 'foo'); $this->assertEqual($result[1], 'bar'); // Clear the cache and re-test the read MAX_Plugin::cleanPluginCache('Maintenance', 'Fake'); $result = MAX_Plugin::getCacheForPluginById('foo', 'Maintenance', 'Fake', null, true, $aOptions); $this->assertFalse($result); // Remove the created directory $this->_delDir(MAX_PATH . $aConf['pluginPaths']['var'] . '/cache/Maintenance'); }
/** * Return the cache * (Test if a cache is available and if $doNotTestCacheValidity is false) * * @static * @param string $id Cache id * @param bool $doNotTestCacheValidity If set to true, the cache validity won't be tested * @param array $options Options - see Cache_Lite() * * @return mixed Data of the cache (or false if no cache available) * */ function getCacheById($id, $doNotTestCacheValidity = true, $options = null) { return MAX_Plugin::getCacheForPluginById($id, $this->module, $this->package, $this->name, $doNotTestCacheValidity, $options); }