/** * display method * * @param mixed $identifier null * @param mixed $value null * @param mixed $default null * @return void * @access public */ function display($identifier = null, $value = null, $default = null) { if (!isset($this->_cache[$identifier])) { $this->_cache[$identifier] = MiCache::data('MiEnums.Enum', 'values', $identifier); } if (isset($this->_cache[$identifier][$value])) { return $this->_cache[$identifier][$value]; } if (!$default) { return MiCache::data('MiEnums.Enum', 'defaultValue', $identifier); } return $default; }
/** * Custom find types, as per Matt Curry's method * * @param string $type * @param array $options * @return mixed array|integer|boolean * @access public * @author Matt Curry * @link http://github.com/mcurry/find */ function find($type, $options = array()) { $method = null; if (is_string($type)) { $method = sprintf('__find%s', Inflector::camelize($type)); } if ($method && method_exists($this, $method)) { $return = $this->{$method}($options); if ($this->query != null) { unset($this->query['paginate']); $query = $this->query; $this->query = null; return $query; } return $return; } if (!empty($options['blacklist'])) { $options['blacklist'] = (array) $options['blacklist']; $options['fields'] = isset($options['fields']) ? $options['fields'] : array_keys($this->schema()); $options['fields'] = array_diff($options['fields'], $options['blacklist']); unset($options['blacklist']); } if (!empty($options['cache'])) { if (!class_exists('MiCache')) { App::import('Vendor', 'mi_cache'); } if (is_int($options['cache'])) { MiCache::config(array('duration' => $options['cache'])); } unset($options['cache']); return MiCache::data($this->alias, 'find', $type, $options); } if (!in_array($type, array_keys($this->_findMethods))) { diebug(array($type, $options)); $calledFrom = debug_backtrace(); CakeLog::write('error', "Unknown method {$this->alias}->{$method} in " . substr(str_replace(ROOT, '', $calledFrom[0]['file']), 1) . ' on line ' . $calledFrom[0]['line']); return false; } $args = func_get_args(); return call_user_func_array(array('parent', 'find'), $args); }
/** * testDataCacheDisabled method * * @return void * @access public */ public function testDataCacheDisabled() { $cacheDisabled = Configure::read('Cache.disable'); Configure::write('Cache.disable', true); $this->expectError('returnMicrotime'); $time = MiCache::data('MiTestModel', 'returnMicrotime'); do { $this->expectError('returnMicrotime'); $directTime = ClassRegistry::init('MiTestModel')->returnMicrotime(); } while ($directTime === $time); $this->expectError('returnMicrotime'); $notCachedTime = MiCache::data('MiTestModel', 'returnMicrotime'); $this->assertNotIdentical($time, $notCachedTime); Configure::write('Cache.disable', $cacheDisabled); }
/** * 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; }
/** * Return the enumerated values for the specified field. * * @param mixed $Model * @param string $field '' * @param bool $autoPopulate true * @return void * @access public */ function enumValues(&$Model, $field = '', $autoPopulate = true) { if (!$field) { $fields = $this->enumFields($Model); $return = array(); foreach ($fields as $field) { $return[$field] = $this->enumFields($Model, $field, $autoPopulate); } return $return; } App::import('Vendor', 'Mi.MiCache'); return MiCache::data('MiEnums.Enum', 'values', $Model->name . '.' . $field, $Model->useDbConfig, $autoPopulate); }
/** * url method * * @param mixed $url * @param bool $full false * @return void * @access public */ function url($url, $full = false) { if (is_a($this, 'SeoComponent')) { $_this =& $this; } else { $_this =& SeoComponent::getInstance(); } $domain = null; if (is_array($url)) { $url = $_this->sortUrl($url); if (array_key_exists('domain', $url)) { if (!strpos($url['domain'], '.')) { $site = Configure::read('Site.id'); if ($url['domain'] == $site) { unset($url['domain']); } else { $url['domain'] = MiCache::data('Site', 'field', 'domain', array('id' => $url['domain'])); } } elseif ($url['domain'] == Configure::read('Seo.maindomain')) { unset($url['domain']); } if (!empty($url['domain'])) { $domain = $url['domain']; } unset($url['domain']); } } $_url = Router::url($url); if (!$domain) { return $_url; } static $s = false; if ($s === false) { if (env('HTTPS')) { $s = 's'; } else { $s = null; } } return 'http' . $s . '://' . $domain . $_url; }
/** * 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)); } }