当前位置: 首页>>代码示例>>PHP>>正文


PHP Cache::write方法代码示例

本文整理汇总了PHP中Cake\Cache\Cache::write方法的典型用法代码示例。如果您正苦于以下问题:PHP Cache::write方法的具体用法?PHP Cache::write怎么用?PHP Cache::write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Cake\Cache\Cache的用法示例。


在下文中一共展示了Cache::write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: afterDispatch

 public function afterDispatch(Event $event, Request $request, Response $response)
 {
     if (Configure::read('debug') || !isset($request->params['cache']) || $request->params['cache'] !== true) {
         return;
     }
     unset($request->params['cache']);
     $cacheKey = $this->_getCacheKey($request);
     if ($cacheKey !== false) {
         $content = $response->body();
         Cache::write($cacheKey, $content, 'wasabi/cms/pages');
     }
 }
开发者ID:wasabi-cms,项目名称:cms,代码行数:12,代码来源:DispatcherListener.php

示例2: getAll

 /**
  * Get all options
  *
  * @param bool $force Force
  * @return array|mixed
  */
 public static function getAll($force = false)
 {
     if ($force === true || self::$_config['cache'] === false || self::$_config['cache'] === true && !Cache::read(self::$_config['cache_name'])) {
         $options = self::$_table->find('all');
         $optionsArray = [];
         foreach ($options as $v) {
             $value = $v->{self::$_config['column_value']};
             $setting = Settings::getSetting($v->{self::$_config['column_key']});
             if (!is_null($setting)) {
                 switch ($setting['type']) {
                     case 'boolean':
                         $value = boolval($value);
                         break;
                     case 'integer':
                         $value = intval($value);
                         break;
                     case 'float':
                         $value = floatval($value);
                         break;
                 }
             }
             $optionsArray[$v->{self::$_config['column_key']}] = $value;
         }
         if (self::$_config['cache'] === true) {
             Cache::write(self::$_config['cache_name'], $optionsArray, self::$_config['cache_config']);
         }
         return $optionsArray;
     }
     return Cache::read(self::$_config['cache_name']);
 }
开发者ID:ThreeCMS,项目名称:ThreeCMS,代码行数:36,代码来源:SettingsData.php

示例3: backendLayoutVars

 /**
  * Prepares some variables used in "default.ctp" layout, such as skin color to use,
  * pending comments counter, etc.
  *
  * @return array Associative array
  */
 function backendLayoutVars()
 {
     $layoutOptions = [];
     $skin = theme()->settings('skin');
     $boxClass = 'success';
     $pendingComments = Cache::read('pending_comments', 'pending_comments');
     if ($pendingComments === false) {
         $pendingComments = TableRegistry::get('Comment.Comments')->find()->where(['Comments.status' => 'pending', 'Comments.table_alias' => 'contents'])->count();
         Cache::write('pending_comments', $pendingComments, 'pending_comments');
     }
     $pendingComments = !$pendingComments ? '' : $pendingComments;
     if (strpos($skin, 'blue') !== false || strpos($skin, 'black') !== false) {
         $boxClass = 'info';
     } elseif (strpos($skin, 'green') !== false) {
         $boxClass = 'success';
     } elseif (strpos($skin, 'red') !== false || strpos($skin, 'purple') !== false) {
         $boxClass = 'danger';
     } elseif (strpos($skin, 'yellow') !== false) {
         $boxClass = 'warning';
     }
     if (theme()->settings('fixed_layout')) {
         $layoutOptions[] = 'fixed';
     }
     if (theme()->settings('boxed_layout')) {
         $layoutOptions[] = 'layout-boxed';
     }
     if (theme()->settings('collapsed_sidebar')) {
         $layoutOptions[] = 'sidebar-collapse';
     }
     return compact('skin', 'layoutOptions', 'boxClass', 'pendingComments');
 }
开发者ID:quickapps-themes,项目名称:backend-theme,代码行数:37,代码来源:bootstrap.php

示例4: _connect

 /**
  * Establishes a connection to the salesforce server
  *
  * @param array $config configuration to be used for creating connection
  * @return bool true on success
  */
 protected function _connect(array $config)
 {
     $this->config = $config;
     if (empty($this->config['my_wsdl'])) {
         throw new \ErrorException("A WSDL needs to be provided");
     } else {
         $wsdl = CONFIG . DS . $this->config['my_wsdl'];
     }
     $mySforceConnection = new \SforceEnterpriseClient();
     $mySoapClient = $mySforceConnection->createConnection($wsdl);
     $sflogin = (array) Cache::read('salesforce_login', 'salesforce');
     if (!empty($sflogin['sessionId'])) {
         $mySforceConnection->setSessionHeader($sflogin['sessionId']);
         $mySforceConnection->setEndPoint($sflogin['serverUrl']);
     } else {
         try {
             $mylogin = $mySforceConnection->login($this->config['username'], $this->config['password']);
             $sflogin = array('sessionId' => $mylogin->sessionId, 'serverUrl' => $mylogin->serverUrl);
             Cache::write('salesforce_login', $sflogin, 'salesforce');
         } catch (Exception $e) {
             $this->log("Error logging into salesforce - Salesforce down?");
             $this->log("Username: " . $this->config['username']);
             $this->log("Password: " . $this->config['password']);
         }
     }
     $this->client = $mySforceConnection;
     $this->connected = true;
     return $this->connected;
 }
开发者ID:voycey,项目名称:cakephp-salesforce,代码行数:35,代码来源:SalesforceDriverTrait.php

示例5: index

 public function index()
 {
     if (($books = Cache::read('exlibrisBooksIndex')) === false) {
         $books = $this->Books->find('all')->contain('Publishers')->all();
         Cache::write('exlibrisBooksIndex', $books);
     }
     $this->set('books', $books);
     $this->set('_serialize', ['books']);
 }
开发者ID:matthiasmoritz,项目名称:exlibris,代码行数:9,代码来源:BooksController.php

示例6: _writeCache

 /**
  * Write the data into the Cache with the passed key.
  *
  * @param int|object|string $data The data to save in the Cache.
  * @param string $key The key to save the data.
  *
  * @return bool
  */
 protected function _writeCache($data, $key)
 {
     if (empty($data) || empty($key)) {
         return true;
     }
     $result = Cache::write($key, $data, 'statistics');
     if ($result) {
         return true;
     }
     return false;
 }
开发者ID:Xety,项目名称:Xeta,代码行数:19,代码来源:Statistics.php

示例7: _latest

 /**
  * Internal method to get the latest photos
  * @param int $limit Limit
  * @return array
  * @uses MeInstagram\Utility\Instagram::recent()
  */
 protected function _latest($limit = 15)
 {
     //Tries to get data from the cache
     $photos = Cache::read($cache = sprintf('latest_%s', $limit), 'instagram');
     //If the data are not available from the cache
     if (empty($photos)) {
         list($photos) = Instagram::recent(null, $limit);
         Cache::write($cache, $photos, 'instagram');
     }
     return $photos;
 }
开发者ID:mirko-pagliai,项目名称:me-instagram,代码行数:17,代码来源:PhotosCell.php

示例8: view

 public function view($slug)
 {
     $pagina = Cache::read('pagina_view_' . $slug);
     if ($pagina === false) {
         $pagina = $this->Paginas->getPaginaBySlug($slug);
         Cache::write('pagina_view_' . $slug, $pagina);
     }
     if (!$pagina) {
         throw new NotFoundException();
     }
     $this->set(compact('pagina'));
 }
开发者ID:richellyitalo,项目名称:estudoscakephp,代码行数:12,代码来源:PaginasController.php

示例9: _writeFailedLogin

 /**
  * Write user failed login.
  *
  * @param Controller $controller
  * @return void
  */
 protected function _writeFailedLogin(Controller $controller)
 {
     $cacheConfig = 'auth';
     if ($controller->request->param('prefix') == 'admin') {
         $cacheConfig .= '_admin';
     }
     $cacheName = 'failed_' . $controller->request->data('username');
     $cacheValue = (int) Cache::read($cacheName, $cacheConfig);
     $cookieVal = $controller->Cookie->read('fail.auth');
     $controller->Cookie->config(['expires' => '+300 seconds']);
     $controller->Cookie->write('fail.auth', (int) $cookieVal + 1);
     Cache::write($cacheName, (int) $cacheValue + 1, $cacheConfig);
 }
开发者ID:Cheren,项目名称:union,代码行数:19,代码来源:LoginFailedTrait.php

示例10: login

 /**
  * Renders the login form.
  *
  * @return \Cake\Network\Response|null
  */
 public function login()
 {
     $this->loadModel('User.Users');
     $this->viewBuilder()->layout('login');
     if ($this->request->is('post')) {
         $loginBlocking = plugin('User')->settings('failed_login_attempts') && plugin('User')->settings('failed_login_attempts_block_seconds');
         $continue = true;
         if ($loginBlocking) {
             Cache::config('users_login', ['duration' => '+' . plugin('User')->settings('failed_login_attempts_block_seconds') . ' seconds', 'path' => CACHE, 'engine' => 'File', 'prefix' => 'qa_', 'groups' => ['acl']]);
             $cacheName = 'login_failed_' . env('REMOTE_ADDR');
             $cache = Cache::read($cacheName, 'users_login');
             if ($cache && $cache['attempts'] >= plugin('User')->settings('failed_login_attempts')) {
                 $blockTime = (int) plugin('User')->settings('failed_login_attempts_block_seconds');
                 $this->Flash->warning(__d('user', 'You have reached the maximum number of login attempts. Try again in {0} minutes.', $blockTime / 60));
                 $continue = false;
             }
         }
         if ($continue) {
             $user = $this->Auth->identify();
             if ($user) {
                 $this->Auth->setUser($user);
                 if (!empty($user['id'])) {
                     try {
                         $user = $this->Users->get($user['id']);
                         if ($user) {
                             $this->Users->touch($user, 'Users.login');
                             $this->Users->save($user);
                         }
                     } catch (\Exception $e) {
                         // invalid user
                     }
                 }
                 return $this->redirect($this->Auth->redirectUrl());
             } else {
                 if ($loginBlocking && isset($cache) && isset($cacheName)) {
                     $cacheStruct = ['attempts' => 0, 'last_attempt' => 0, 'ip' => '', 'request_log' => []];
                     $cache = array_merge($cacheStruct, $cache);
                     $cache['attempts'] += 1;
                     $cache['last_attempt'] = time();
                     $cache['ip'] = env('REMOTE_ADDR');
                     $cache['request_log'][] = ['data' => $this->request->data, 'time' => time()];
                     Cache::write($cacheName, $cache, 'users_login');
                 }
                 $this->Flash->danger(__d('user', 'Username or password is incorrect.'));
             }
         }
     }
     $user = $this->Users->newEntity();
     $this->title(__d('user', 'Login'));
     $this->set(compact('user'));
 }
开发者ID:quickapps-plugins,项目名称:user,代码行数:56,代码来源:UserSignTrait.php

示例11: describe

 /**
  * {@inheritDoc}
  *
  */
 public function describe($name, array $options = [])
 {
     $options += ['forceRefresh' => false];
     $cacheConfig = $this->cacheMetadata();
     $cacheKey = $this->cacheKey($name);
     if (!empty($cacheConfig) && !$options['forceRefresh']) {
         $cached = Cache::read($cacheKey, $cacheConfig);
         if ($cached !== false) {
             return $cached;
         }
     }
     $table = parent::describe($name, $options);
     if (!empty($cacheConfig)) {
         Cache::write($cacheKey, $table, $cacheConfig);
     }
     return $table;
 }
开发者ID:wepbunny,项目名称:cake2,代码行数:21,代码来源:CachedCollection.php

示例12: accessToken

 /**
  * Returns a application access token.
  *
  * @return string|bool The access token or false in case of a failure
  */
 public function accessToken()
 {
     $cacheKey = 'twitter-' . $this->config('name') . '-token';
     if (Cache::read($cacheKey) !== false) {
         return Cache::read($cacheKey);
     }
     $bearerToken = $this->bearerToken();
     if (!$bearerToken) {
         return false;
     }
     $client = new Client(['headers' => ['Authorization' => 'Basic ' . $bearerToken], 'host' => 'api.twitter.com', 'scheme' => 'https']);
     $response = $client->post('/oauth2/token', ['grant_type' => 'client_credentials']);
     if (!$response->isOk() || !$response->json['token_type']) {
         return false;
     }
     Cache::write($cacheKey, $response->json['access_token']);
     return $response->json['access_token'];
 }
开发者ID:cvo-technologies,项目名称:cakephp-twitter,代码行数:23,代码来源:Twitter.php

示例13: getApiControllers

 /**
  * Returns a list of Controller names found in /src/Controller/Api.
  *
  * @return array List holding sorted Controller names
  */
 public static function getApiControllers()
 {
     $cached = Cache::read('api_controllers');
     if ($cached) {
         return $cached;
     }
     $dir = new Folder(APP . 'Controller' . DS . Inflector::camelize(Configure::read('App++.Api.prefix')));
     $controllerFiles = $dir->find('.*Controller\\.php');
     if (!$controllerFiles) {
         return false;
     }
     $result = [];
     foreach ($controllerFiles as $controllerFile) {
         $result[] = substr($controllerFile, 0, strlen($controllerFile) - 14);
     }
     sort($result);
     Cache::write('api_controllers', $result);
     return $result;
 }
开发者ID:alt3,项目名称:cakephp-app-configurator,代码行数:24,代码来源:PlusPlus.php

示例14: main

 public function main()
 {
     //Cache::clear(false);
     foreach ($this->Incidents->filterTimes as $filter_string => $filter) {
         foreach ($this->Incidents->summarizableFields as $field) {
             $this->out("processing " . $filter_string . ":" . $field);
             $entriesWithCount = $this->Reports->getRelatedByField($field, 25, false, false, $filter["limit"]);
             $entriesWithCount = json_encode($entriesWithCount);
             Cache::write($field . '_' . $filter_string, $entriesWithCount);
         }
         $query = array('group' => 'grouped_by', 'order' => 'Incidents.created');
         if (isset($filter["limit"])) {
             $query["conditions"] = array('Incidents.created >=' => $filter["limit"]);
         }
         $downloadStats = $this->Incidents->find('all', $query);
         $downloadStats->select(['grouped_by' => $filter["group"], 'date' => "DATE_FORMAT(Incidents.created, '%a %b %d %Y %T')", 'count' => $downloadStats->func()->count('*')]);
         $downloadStats = json_encode($downloadStats->toArray());
         Cache::write('downloadStats_' . $filter_string, $downloadStats);
     }
 }
开发者ID:ujjwalwahi,项目名称:error-reporting-server,代码行数:20,代码来源:StatsShell.php

示例15: _icons

 protected function _icons()
 {
     $useCache = true;
     if (!empty($this->request->params['named']['reset'])) {
         $useCache = false;
     }
     if ($useCache && ($iconNames = Cache::read('country_icon_names')) !== false) {
         $this->Flash->info('Cache Used');
         return $iconNames;
     }
     $handle = new Folder($this->imageFolder);
     $icons = $handle->read(true, true);
     $iconNames = [];
     foreach ($icons[1] as $icon) {
         # only use files (not folders)
         $iconNames[] = strtoupper(extractPathInfo('filename', $icon));
     }
     Cache::write('country_icon_names', $iconNames);
     return $iconNames;
 }
开发者ID:BDhulia,项目名称:cakephp-data,代码行数:20,代码来源:CountriesController.php


注:本文中的Cake\Cache\Cache::write方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。