本文整理汇总了PHP中Cache::read方法的典型用法代码示例。如果您正苦于以下问题:PHP Cache::read方法的具体用法?PHP Cache::read怎么用?PHP Cache::read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cache
的用法示例。
在下文中一共展示了Cache::read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: GetRandomUser
function GetRandomUser()
{
//SET GENERAL SETTINGS
if (($settings = Cache::read('settings')) === false) {
$SETTING = ClassRegistry::Init('Setting');
$settings = $SETTING->find('first');
Cache::write('settings', $settings);
}
$this->Cookie->domain = $settings['Setting']['site_domain'];
$this->Cookie->path = "/";
$cookie_rand = $this->Cookie->read('rand_user');
$userlogin = $this->General->my_decrypt($this->Cookie->read('userlogin'));
$RandomUser = ClassRegistry::Init("RandomUser");
if (!is_null($cookie_rand)) {
return $cookie_rand;
} else {
$ip = $_SERVER['REMOTE_ADDR'];
//CHEK IP FIRST
$cond = !is_null($userlogin) ? array("RandomUser.user_id" => $userlogin, "RandomUser.ip_address" => $ip) : array("RandomUser.ip_address " => $ip, 'RandomUser.user_id IS NULL');
$find = $RandomUser->find("first", array('conditions' => $cond));
if ($find == false) {
$rand_user = $this->GenerateRandom();
$this->Cookie->write('rand_user', $rand_user, false, 24 * 3600 * 30, $settings['Setting']['site_domain']);
return $rand_user;
} else {
$rand_user = $find['RandomUser']['rand_id'];
$this->Cookie->write('rand_user', $rand_user, false, 24 * 3600 * 30, $settings['Setting']['site_domain']);
return $find['RandomUser']['rand_id'];
}
}
}
示例2: smarty_function_language_box
function smarty_function_language_box($params, $template)
{
// Cache the output.
$cache_name = 'vam_language_box_output' . (isset($params['template']) ? '_' . $params['template'] : '') . '_' . $_SESSION['Customer']['language_id'];
$language_box_output = Cache::read($cache_name);
if ($language_box_output === false) {
ob_start();
global $content;
App::import('Component', 'Smarty');
$Smarty =& new SmartyComponent();
App::import('Model', 'Language');
$Language =& new Language();
$languages = $Language->find('all', array('conditions' => array('active' => '1')));
if (count($languages) == 1) {
return;
}
$keyed_languages = array();
foreach ($languages as $language) {
$language['Language']['url'] = BASE . '/languages/pick_language/' . $language['Language']['id'];
$language['Language']['image'] = BASE . '/img/flags/' . $language['Language']['iso_code_2'] . '.png';
$keyed_languages[] = $language['Language'];
}
$vars = array('languages' => $keyed_languages);
$display_template = $Smarty->load_template($params, 'language_box');
$Smarty->display($display_template, $vars);
// Write the output to cache and echo them
$language_box_output = @ob_get_contents();
ob_end_clean();
Cache::write($cache_name, $language_box_output);
}
echo $language_box_output;
}
示例3: beforeRender
/**
* beforeRender callback function
*
* @return array contents for panel
**/
public function beforeRender(Controller $controller)
{
$cacheKey = $controller->Toolbar->cacheKey;
$toolbarHistory = Cache::read($cacheKey, 'debug_kit');
$historyStates = array();
if (is_array($toolbarHistory) && !empty($toolbarHistory)) {
$prefix = array();
if (!empty($controller->request->params['prefix'])) {
$prefix[$controller->request->params['prefix']] = false;
}
foreach ($toolbarHistory as $i => $state) {
if (!isset($state['request']['content']['url'])) {
continue;
}
$title = $state['request']['content']['url'];
$query = @$state['request']['content']['query'];
if (isset($query['url'])) {
unset($query['url']);
}
if (!empty($query)) {
$title .= '?' . urldecode(http_build_query($query));
}
$historyStates[] = array('title' => $title, 'url' => array_merge($prefix, array('plugin' => 'debug_kit', 'controller' => 'toolbar_access', 'action' => 'history_state', $i + 1)));
}
}
if (count($historyStates) >= $this->history) {
array_pop($historyStates);
}
return $historyStates;
}
示例4: beforeFilter
public function beforeFilter()
{
$this->Auth->loginAction = array('controller' => 'users', 'action' => 'login', 'admin' => false);
$this->Auth->loginRedirect = array('controller' => 'users', 'action' => 'index', 'admin' => true);
$this->Auth->logoutRedirect = array('controller' => 'contents', 'action' => 'homepage', 'admin' => false, 'vendor' => false);
$this->Auth->authorize = array('Controller');
$this->Auth->authenticate = array(AuthComponent::ALL => array('userModel' => 'User', 'fields' => array('username' => 'username', 'password' => 'password'), 'scope' => array('User.active' => 1)), 'Form');
if (isset($this->request->params['admin']) && $this->request->params['prefix'] == 'admin') {
$this->set('authUser', $this->Auth->user());
$this->layout = 'admin';
} elseif (isset($this->request->params['vendor']) && $this->request->params['prefix'] == 'vendor') {
$this->set('authUser', $this->Auth->user());
$this->layout = 'vendor';
} else {
$this->Auth->allow();
$menucategories = Cache::read('menucategories');
if (!$menucategories) {
$menucategories = ClassRegistry::init('Product')->find('all', array('recursive' => -1, 'contain' => array('User', 'Category'), 'fields' => array('Category.id', 'Category.name', 'Category.slug'), 'conditions' => array('User.active' => 1, 'Product.active' => 1, 'Product.category_id >' => 0, 'Category.id >' => 0), 'order' => array('Category.name' => 'ASC'), 'group' => array('Category.id')));
Cache::set(array('duration' => '+10 minutes'));
Cache::write('menucategories', $menucategories);
}
$this->set(compact('menucategories'));
$menuvendors = Cache::read('menuvendors');
if (!$menuvendors) {
$menuvendors = ClassRegistry::init('User')->getVendors();
Cache::set(array('duration' => '+10 minutes'));
Cache::write('menuvendors', $menuvendors);
}
$this->set(compact('menuvendors'));
}
if ($this->RequestHandler->isAjax()) {
$this->layout = 'ajax';
}
$this->AutoLogin->settings = array('model' => 'Member', 'username' => 'name', 'password' => 'pass', 'plugin' => '', 'controller' => 'members', 'loginAction' => 'signin', 'logoutAction' => 'signout', 'cookieName' => 'rememberMe', 'expires' => '+1 month', 'active' => true, 'redirect' => true, 'requirePrompt' => true);
}
示例5: admin_index
/**
* admin_index
*
* @param id integer aco id, when null, the root ACO is used
* @return void
*/
public function admin_index($id = null, $level = null)
{
$this->set('title_for_layout', __('Permissions'));
if ($id == null) {
$root = $this->AclAco->node('controllers');
$root = $root[0];
} else {
$root = $this->AclAco->read(null, $id);
}
if ($level !== null) {
$level++;
}
$acos = $this->AclAco->getChildren($root['Aco']['id']);
$roles = $this->Role->find('list');
$this->set(compact('acos', 'roles', 'level'));
$aros = $this->AclAro->getRoles($roles);
if ($this->RequestHandler->ext == 'json') {
$options = array_intersect_key($this->request->query, array('perms' => null, 'urls' => null));
$cacheName = 'permissions_aco_' . $root['Aco']['id'];
$permissions = Cache::read($cacheName, 'permissions');
if ($permissions === false) {
$permissions = $this->AclPermission->format($acos, $aros, $options);
Cache::write($cacheName, $permissions, 'permissions');
}
} else {
$permissions = array();
}
$this->set(compact('aros', 'permissions'));
}
示例6: testCache
/**
* testCache
*
*/
public function testCache()
{
$result = Cache::write('hoge', 'fuga');
$this->assertTrue($result);
$result = Cache::read('hoge');
$this->assertIdentical($result, 'fuga');
}
示例7: admin_index
/**
* admin_index
*
* @return void
*/
public function admin_index()
{
$settingLang = Cache::read('settings', "admin");
$this->User->locale = $settingLang[0]['Setting']['value'];
$this->paginate['User']['order'] = 'User.id Desc';
$this->set('users', $this->paginate('User'));
}
示例8: readCache
/**
* Get the cache key config if we have cache setup
* @param string key
* @return mixed boolean false or
*/
public static function readCache($key)
{
if (self::getConfig('cache')) {
return Cache::read($key, 'queue');
}
return false;
}
示例9: common
public function common($params)
{
$Register = Register::getInstance();
$output = '';
if (!strpos($params, '{{ users_rating }}')) {
return $params;
}
$Cache = new Cache();
$Cache->lifeTime = 600;
if ($Cache->check('pl_users_rating')) {
$users = $Cache->read('pl_users_rating');
$users = json_decode($users, true);
} else {
$users = $this->DB->select('users', DB_ALL, array('order' => '`rating` DESC', 'limit' => $this->limit));
//$users = $this->DB->query($sql);
$Cache->write(json_encode($users), 'pl_users_rating', array());
}
if (!empty($users)) {
foreach ($users as $key => $user) {
$link = get_link($user['name'], getProfileUrl($user['id']));
$ava = file_exists(ROOT . '/sys/avatars/' . $user['id'] . '.jpg') ? get_url('/sys/avatars/' . $user['id'] . '.jpg') : get_url('/sys/img/noavatar.png');
$output .= sprintf($this->wrap, $ava, $link, $user['rating'], $user['posts']);
}
}
$output .= '<div class="etopu">' . get_link('Весь рейтинг', '/users/index?order=rating') . '</div>';
return str_replace('{{ users_rating }}', $output, $params);
}
示例10: retrieveBySlug
/**
* Retrieve SEO meta data - including basic caching.
*
* @param string $slug
* @param array $options
* @return array
*/
public function retrieveBySlug($slug, $options = array())
{
$options = array_merge(array('record' => false, 'seo_only' => false, 'skip' => array()), (array) $options);
$hash = md5(serialize($options));
if (($record = Cache::read('seo.slug.' . $hash)) !== false) {
return $record;
}
$seo = $this->findBySlug($slug);
if (!$seo) {
return array();
}
if ($options['seo_only']) {
$keys = array('title_for_layout', 'description', 'keywords', 'canonical', 'h2_for_layout');
$seo[$this->alias] = array_intersect_key($seo[$this->alias], array_combine($keys, $keys));
}
if (!empty($options['skip'])) {
$seo[$this->alias] = array_diff_key($seo[$this->alias], (array) $options['skip']);
}
if ($options['record']) {
Cache::write('seo.slug.' . $hash, $seo);
return $seo;
}
Cache::write('seo.slug.' . $hash, $seo[$this->alias]);
return $seo[$this->alias];
}
示例11: __loadEventHandlers
/**
* Loads all available event handler classes for enabled plugins
*
*/
private function __loadEventHandlers()
{
$this->__eventHandlerCache = Cache::read('event_handlers', 'core');
if (empty($this->__eventHandlerCache)) {
App::import('Core', 'Folder');
$folder = new Folder();
$pluginsPaths = App::path('plugins');
foreach ($pluginsPaths as $pluginsPath) {
$folder->cd($pluginsPath);
$plugins = $folder->read();
$plugins = $plugins[0];
if (count($plugins)) {
foreach ($plugins as $pluginName) {
$filename = $pluginsPath . $pluginName . DS . $pluginName . '_events.php';
$className = Inflector::camelize($pluginName . '_events');
if (file_exists($filename)) {
if (EventCore::__loadEventClass($className, $filename)) {
EventCore::__getAvailableHandlers($this->__eventClasses[$className]);
}
}
}
}
}
Cache::write('event_handlers', $this->__eventHandlerCache, 'core');
}
}
示例12: url
/**
* Builds an URL array based on a preset.
*
* @param array $data Data for the URL params.
* @param string $identifier
* @param array $options
* @throws RuntimeException
* @throws InvalidArgumentException
* @return array
*/
public static function url($data, $identifier, $options = array())
{
if (self::$_cacheConfig !== false) {
$cacheKey = md5(serialize($data) . serialize($options)) . $identifier;
$url = Cache::read($cacheKey, self::$_cacheConfig);
if (!empty($url)) {
return $url;
}
}
if (is_string($identifier)) {
$preset = self::getTemplate($identifier);
} elseif (is_array($identifier)) {
$preset = $identifier;
} else {
throw new \InvalidArgumentException(__d('bz_utils', 'Must be string or array!'));
}
$url = self::_buildUrlArray($data, $preset);
if (isset($options['string']) && $options['string'] === true) {
$fullBase = isset($options['fullBase']) && $options['fullBase'] === true;
$url = Router::url($url, $fullBase);
if (self::$_cacheConfig !== false) {
Cache::write($cacheKey, $url, self::$_cacheConfig);
}
return $url;
}
if (self::$_cacheConfig !== false) {
Cache::write($cacheKey, $url, self::$_cacheConfig);
}
return $url;
}
示例13: smarty_block_lang
function smarty_block_lang($params, $content, $template, &$repeat)
{
if (is_null($content)) {
return;
}
// Start caching
$cache_name = 'vam_lang_' . $_SESSION['Customer']['language_id'] . '_' . $content;
$output = Cache::read($cache_name);
if ($output === false) {
ob_start();
App::import('Model', 'DefinedLanguage');
$DefinedLanguage =& new DefinedLanguage();
$language_content = $DefinedLanguage->find(array('language_id' => $_SESSION['Customer']['language_id'], 'key' => $content));
if (empty($language_content['DefinedLanguage']['value'])) {
//$output = "Error! Empty language value for: " . $content;
$lang_output = $content;
} else {
$lang_output = $language_content['DefinedLanguage']['value'];
}
echo $lang_output;
// End cache
$output = @ob_get_contents();
ob_end_clean();
Cache::write($cache_name, $output);
}
echo $output;
}
示例14: load
/**
* Find all defined callbacks in the app or other plugins
*
* @param undefined $cached
* @return void
* @access public
*/
public function load()
{
$cached = Cache::read('_plugin_callbacks_', '_cake_models_');
if ($cached !== false) {
$this->settings = $cached;
return $cached;
}
App::import('Folder');
$Folder = new Folder($this->path . 'plugins');
$folders = current($Folder->ls());
$files = array();
foreach ($folders as $folder) {
if ($Folder->cd($this->path . 'models' . DS . 'callbacks')) {
$files = $Folder->findRecursive('([a-z_]+)_' . $folder . '.php');
}
$files = array_flip($files);
foreach ($folders as $_folder) {
if ($Folder->cd($this->path . 'plugins' . DS . $_folder . DS . 'models' . DS . 'callbacks')) {
$files = array_merge($files, array_flip($Folder->findRecursive('([a-z_]+)_' . $folder . '.php')));
}
}
foreach (array_keys($files) as $k => $file) {
if (!preg_match_all('/models\\/callbacks\\/([a-z_]+)_' . $folder . '\\.php/i', $file, $matches)) {
continue;
}
$plugin = current($matches[1]);
if (empty($plugin)) {
$plugin = 'app';
}
$callbackName = Inflector::camelize(sprintf('%s_%s', $plugin, $folder));
$this->settings[$folder][$plugin] = $callbackName;
}
}
Cache::write('_plugin_callbacks_', $this->settings, '_cake_models_');
}
示例15: getSetting
/**
* getSetting
*
*/
public static function getSetting(Model $model, $key = null, $force = false)
{
$prefix = Configure::read('Setting.prefix');
if ($force) {
$setting = $model;
return $setting->getSettingFromDatasource($key);
}
$cache = Cache::read($prefix . 'Setting.cache');
if ($cache === false || empty($cache[$key])) {
$setting = $model;
self::clearCache($model);
Cache::write($prefix . 'Setting.cache', $setting->getSettingFromDatasource());
$cache = Cache::read($prefix . 'Setting.cache');
}
if ($cache) {
$settings = Configure::read('Setting.settings');
if ($key === null) {
return $cache;
} else {
$keys = array();
foreach (array_intersect((array) $key, array_keys($settings)) as $k) {
if (!array_key_exists($k, $cache) || $cache[$k] === null) {
$setting = $model;
return $setting->getSettingFromDatasource($key);
}
$keys[$k] = $cache[$k];
}
if ($key !== null && count($keys) === 1) {
return array_shift($keys);
}
return false;
}
}
return null;
}