當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Cache::read方法代碼示例

本文整理匯總了PHP中Cake\Cache\Cache::read方法的典型用法代碼示例。如果您正苦於以下問題:PHP Cache::read方法的具體用法?PHP Cache::read怎麽用?PHP Cache::read使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Cake\Cache\Cache的用法示例。


在下文中一共展示了Cache::read方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: initMenu

 /**
  * Ustawienie menu
  */
 private function initMenu()
 {
     $menu = Cache::read('menu-' . $this->userRole);
     if (!isset($menu) || $menu === false) {
         // Pobranie menu z configa
         Configure::load('Admin.app_menu', 'default');
         $menuConfig = Configure::read('menu');
         $that = $this;
         $generateMenu = function ($array) use($that, &$generateMenu) {
             $menu = array();
             foreach ($array as $key => $item) {
                 $link = $item['link'];
                 // czy ma dostep
                 if (!$link || $that->permission->check($link['controller'], $link['action'])) {
                     $childs = [];
                     if (isset($item['childs']) && !empty($item['childs'])) {
                         $childs = $generateMenu($item['childs']);
                         $item['childs'] = $childs;
                     }
                     // Nie dodaje pustych elementów do menu bez linku
                     if (count($childs) == 0 && !$link) {
                         continue;
                     }
                     $menu[$key] = $item;
                 }
             }
             return $menu;
         };
         $menu = $generateMenu($menuConfig);
         Cache::write('menu-' . $this->userRole, $menu);
     }
     $this->set('params', $this->request->params);
     $this->set('menu', $menu);
 }
開發者ID:bartekpie3,項目名稱:cakeAdmiin,代碼行數:37,代碼來源:AppController.php

示例2: testTranslationCaching

 /**
  * testTranslationCaching method
  *
  * @return void
  */
 public function testTranslationCaching()
 {
     $this->skipIf(!Cache::engine('_cake_core_'), 'Missing _cake_core_ cache config, cannot test caching.');
     Configure::write('Config.language', 'cache_test_po');
     // reset internally stored entries
     I18n::clear();
     Cache::clear(false, '_cake_core_');
     $lang = Configure::read('Config.language');
     // make some calls to translate using different domains
     $this->assertEquals('Dom 1 Foo', I18n::translate('dom1.foo', false, 'dom1'));
     $this->assertEquals('Dom 1 Bar', I18n::translate('dom1.bar', false, 'dom1'));
     $domains = I18n::domains();
     $this->assertEquals('Dom 1 Foo', $domains['dom1']['cache_test_po']['LC_MESSAGES']['dom1.foo']);
     // reset internally stored entries
     I18n::clear();
     // now only dom1 should be in cache
     $cachedDom1 = Cache::read('dom1_' . $lang, '_cake_core_');
     $this->assertEquals('Dom 1 Foo', $cachedDom1['LC_MESSAGES']['dom1.foo']);
     $this->assertEquals('Dom 1 Bar', $cachedDom1['LC_MESSAGES']['dom1.bar']);
     // dom2 not in cache
     $this->assertFalse(Cache::read('dom2_' . $lang, '_cake_core_'));
     // translate a item of dom2 (adds dom2 to cache)
     $this->assertEquals('Dom 2 Foo', I18n::translate('dom2.foo', false, 'dom2'));
     // verify dom2 was cached through manual read from cache
     $cachedDom2 = Cache::read('dom2_' . $lang, '_cake_core_');
     $this->assertEquals('Dom 2 Foo', $cachedDom2['LC_MESSAGES']['dom2.foo']);
     $this->assertEquals('Dom 2 Bar', $cachedDom2['LC_MESSAGES']['dom2.bar']);
     // modify cache entry manually to verify that dom1 entries now will be read from cache
     $cachedDom1['LC_MESSAGES']['dom1.foo'] = 'FOO';
     Cache::write('dom1_' . $lang, $cachedDom1, '_cake_core_');
     $this->assertEquals('FOO', I18n::translate('dom1.foo', false, 'dom1'));
 }
開發者ID:ripzappa0924,項目名稱:carte0.0.1,代碼行數:37,代碼來源:I18nTest.php

示例3: get

 /**
  * Get option by key
  *
  * @param string $key Option key
  * @return mixed|null
  */
 public static function get($key)
 {
     if (!($options = Cache::read(self::$_config['cache_name']))) {
         $options = self::getAll();
     }
     return array_key_exists($key, $options) ? $options[$key] : null;
 }
開發者ID:ThreeCMS,項目名稱:ThreeCMS,代碼行數:13,代碼來源:SettingsData.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: testInIndexBehavior

 public function testInIndexBehavior()
 {
     $this->Articles->addBehavior('RelatedContent\\Test\\TestCase\\Model\\Behavior\\TestInRelatedIndexBehavior');
     $this->Articles->addBehavior('RelatedContent\\Test\\TestCase\\Model\\Behavior\\TestHasRelatedBehavior');
     /*$testEntity = $this->Articles->newEntity(['id' => 5, 'title' => 'Test title five']);
     		$this->Articles->save($testEntity);*/
     //<editor-fold desc="Should get two related">
     $firstArticle = $this->Articles->get(1, ['getRelated' => true]);
     $this->assertCount(2, $firstArticle->related);
     //</editor-fold>
     //<editor-fold desc="Should save only one">
     $firstArticle = $this->Articles->patchEntity($firstArticle, ['related-articles' => [['id' => 3, '_joinData' => ['source_table_name' => 'articles', 'target_table_name' => 'articles']]]]);
     $this->Articles->save($firstArticle);
     $firstArticle = $this->Articles->get(1, ['getRelated' => true]);
     $this->assertCount(1, $firstArticle->related);
     //</editor-fold>
     //<editor-fold desc="Test if cache works">
     $newArticle = $this->Articles->newEntity(['id' => 5, 'title' => 'Test title five']);
     $this->Articles->save($newArticle);
     $attachedTables = Cache::read('Related.attachedTables');
     $indexedTables = Cache::read('Related.indexedTables');
     $this->assertCount(1, $attachedTables);
     $this->assertEquals('articles', $attachedTables[0]);
     $this->assertCount(5, $indexedTables['Articles']);
     $this->assertEquals('Test title five', $indexedTables['Articles'][5]);
     $this->Articles->delete($this->Articles->get(3));
     $indexedTables = Cache::read('Related.indexedTables');
     $this->assertCount(4, $indexedTables['Articles']);
     //</editor-fold>
 }
開發者ID:aiphee,項目名稱:cakephp-related-content,代碼行數:30,代碼來源:TestBehaviorsTest.php

示例6: 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

示例7: read

 public function read($id)
 {
     $result = Cache::read($id, $this->cacheKey);
     if ($result) {
         return $result;
     }
     return parent::read($id);
 }
開發者ID:ansidev,項目名稱:cakephp_blog,代碼行數:8,代碼來源:ComboSession.php

示例8: read

 /**
  * Method used to read from a cache session.
  *
  * @param string $id The key of the value to read
  * @return string The value of the key or empty if it does not exist
  */
 public function read($id)
 {
     $value = Cache::read($id, $this->_options['config']);
     if (empty($value)) {
         return '';
     }
     return $value;
 }
開發者ID:JesseDarellMoore,項目名稱:CS499,代碼行數:14,代碼來源:CacheSession.php

示例9: _getIndexedTables

 /**
  * @return mixed
  */
 protected function _getIndexedTables()
 {
     if (($indexed_tables = Cache::read('Related.indexedTables')) === false) {
         $InRelatedIndexBehavior = new InRelatedIndexBehavior(TableRegistry::get(''));
         $InRelatedIndexBehavior->refreshCache();
         $indexed_tables = Cache::read('Related.indexedTables');
     }
     return $indexed_tables;
 }
開發者ID:aiphee,項目名稱:cakephp-related-content,代碼行數:12,代碼來源:RelatedContentController.php

示例10: 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

示例11: testDescribeCache

 /**
  * Tests that schema metadata is cached
  *
  * @return void
  */
 public function testDescribeCache()
 {
     $schema = $this->connection->schemaCollection();
     $table = $this->connection->schemaCollection()->describe('users');
     Cache::delete('test_users', '_cake_model_');
     $schema->cacheMetadata(true);
     $result = $schema->describe('users');
     $this->assertEquals($table, $result);
     $result = Cache::read('test_users', '_cake_model_');
     $this->assertEquals($table, $result);
 }
開發者ID:ripzappa0924,項目名稱:carte0.0.1,代碼行數:16,代碼來源:CollectionTest.php

示例12: _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

示例13: 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

示例14: testDescribeCache

 /**
  * Tests that schema metadata is cached
  *
  * @return void
  */
 public function testDescribeCache()
 {
     $schema = $this->connection->methodSchemaCollection();
     $method = $this->connection->methodSchemaCollection()->describe('CALC.SUM');
     Cache::delete('test_CALC_SUM', '_cake_method_');
     $this->connection->cacheMetadata(true);
     $schema = $this->connection->methodSchemaCollection();
     $result = $schema->describe('CALC.SUM');
     $this->assertEquals($method, $result);
     $result = Cache::read('test_CALC_SUM', '_cake_method_');
     $this->assertEquals($method, $result);
 }
開發者ID:cakedc,項目名稱:cakephp-oracle-driver,代碼行數:17,代碼來源:CollectionTest.php

示例15: find

 /**
  * Creates a new Query for this repository and applies some defaults based
  *  on the type of search that was selected
  * @param string $type The type of query to perform
  * @param array|ArrayAccess $options An array that will be passed to
  *  Query::applyOptions()
  * @return Cake\ORM\Query The query builder
  * @uses setNextToBePublished()
  * @uses $cache
  */
 public function find($type = 'all', $options = [])
 {
     //Gets from cache the timestamp of the next record to be published
     $next = Cache::read('next_to_be_published', $this->cache);
     //If the cache is not valid, it empties the cache
     if ($next && time() >= $next) {
         Cache::clear(false, $this->cache);
         //Sets the next record to be published
         $this->setNextToBePublished();
     }
     return parent::find($type, $options);
 }
開發者ID:mirko-pagliai,項目名稱:me-cms,代碼行數:22,代碼來源:PagesTable.php


注:本文中的Cake\Cache\Cache::read方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。