/** * setting method * * Query the application setting model, if there is no result query Configure::read - and cache * the result * * @param string $cacheKey '' * @param mixed $dummy null * @return void * @access public */ public static function setting($id = '', $aroId = null) { if (MiCache::$setting === null) { MiCache::config(); } if (MiCache::$settings[MiCache::$setting]['batchLoadSettings']) { if (strpos($id, '.')) { $keys = explode('.', $id); $mainId = array_shift($keys); if (!array_key_exists($aroId . '_' . $mainId, MiCache::$_appSettingCache)) { MiCache::$_appSettingCache[$aroId . '_' . $mainId] = MiCache::setting($mainId, $aroId); } $array = MiCache::$_appSettingCache[$aroId . '_' . $mainId]; $j = count($keys); $return = null; if (is_array($array)) { foreach ($keys as $i => $key) { if (!array_key_exists($key, $array)) { $array = null; break; } $array = $array[$key]; } if ($i == $j - 1) { $return = $array; } } if ($return !== null) { return $return; } } } else { if (strpos($id, '.')) { $keys = explode('.', $id, 1); $mainId = array_shift($keys); if (array_key_exists($aroId . '_' . $mainId, MiCache::$_appSettingCache) && array_key_exists($id, MiCache::$_appSettingCache[$aroId . '_' . $mainId])) { return MiCache::$_appSettingCache[$aroId . '_' . $mainId][$id]; } } } if (MiCache::_hasSettingsTable()) { $return = MiCache::data('MiSettings.Setting', 'data', $id, $aroId); if ($return !== null) { return $return; } } $return = Configure::read($id); $cacheKey = MiCache::key(array('MiSettings.Setting', 'data', $id, $aroId)); MiCache::write($cacheKey, $return, MiCache::$setting); return $return; }
/** * testObjectCall method * * Check what happens with arbritary object calls * * @return void * @access public */ public function testObjectCall() { Configure::write('Cache.disable', false); App::import('Core', 'HttpSocket'); $Socket = new HttpSocket(); MiCache::delete($Socket, 'get', 'http://ad7six.com'); $key1 = MiCache::key($Socket, 'get', 'http://ad7six.com'); $return = MiCache::data($Socket, 'get', 'http://ad7six.com'); $this->assertTrue(strpos($return, 'AD7six')); $key2 = MiCache::key($Socket, 'get', 'http://ad7six.com'); $this->assertIdentical($key1, $key2, 'Object state is affecting cache key'); $Socket->reset(); $return = MiCache::data($Socket, 'get', 'http://ad7six.com'); $this->assertTrue(strpos($return, 'AD7six')); $this->assertFalse($Socket->response['status']['code'], 'Result not cached, HttpSocket class still made a request'); $config = MiCache::config(); if ($config['mi_cache']['engine'] === 'MiFile') { $this->assertTrue(file_exists($config['mi_cache']['path'] . $key1)); } MiCache::delete($Socket, 'get', 'http://ad7six.com'); if ($config['mi_cache']['engine'] === 'MiFile') { $this->assertFalse(file_exists($config['mi_cache']['path'] . $key1)); } }