/**
  * 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');
 }
Ejemplo n.º 2
0
 /**
  * Save some data in a cache file
  *
  * @static
  * @param string $data      Data to put in cache (can be another type than strings if automaticSerialization is on)
  * @param string $id        Cache id
  * @param array  $options   Options - see Cache_Lite()
  *
  * @return bool             True if no problem, else false
  *
  */
 function saveCache($data, $id, $options = null)
 {
     return MAX_Plugin::saveCacheForPlugin($data, $id, $this->module, $this->package, $this->name, $options);
 }