/** * A method to delete cached plugin data. * * @static * @param string $module The plugin module name (i.e. /plugins/module directory). * @param string $package The plugin package name (i.e. /plugins/module/package * directory). * @param string $name Optional name of the PHP file which contains the plugin, * otherwise the plugin with the same name as the package * is assumed. * @param string $mode An optional PEAR::Cache_Lite cleaning mode. Default is * 'ingroup', to delete all cached data for the plugin. * @param array $aOptions An optional array of constructor options for * PEAR::Cache_Lite. The default values are those * obtained from {@link MAX_Plugin::prepareCacheOptions()}. * @return boolean True on success, false otherwise. */ function cleanPluginCache($module, $package, $name = null, $mode = 'ingroup', $aOptions = null) { if (is_null($name)) { $name = $package; } if (is_null($aOptions)) { $aOptions = MAX_Plugin::prepareCacheOptions($module, $package); } $oCache = new Cache_Lite($aOptions); return $oCache->clean($name, $mode); }
/** * 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'); }