/**
  * 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');
 }
示例#2
0
 /**
  * Save some data in a cache file
  *
  * @static
  * @param string $mode  Flush cache mode : 'old', 'ingroup', 'notingroup'
  *
  * @return bool         True if no problem, else false
  *
  */
 function cleanCache($mode = 'ingroup')
 {
     return MAX_Plugin::cleanPluginCache($this->module, $this->package, $this->name, $mode);
 }