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


PHP Cache::readMany方法代码示例

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


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

示例1: view

 /**
  * Lists posts for a category
  * @param string $slug Category slug
  * @return \Cake\Network\Response|null|void
  * @throws RecordNotFoundException
  */
 public function view($slug = null)
 {
     //The category can be passed as query string, from a widget
     if ($this->request->query('q')) {
         return $this->redirect([$this->request->query('q')]);
     }
     $page = $this->request->query('page') ? $this->request->query('page') : 1;
     //Sets the cache name
     $cache = sprintf('category_%s_limit_%s_page_%s', md5($slug), $this->paginate['limit'], $page);
     //Tries to get data from the cache
     list($posts, $paging) = array_values(Cache::readMany([$cache, sprintf('%s_paging', $cache)], $this->PostsCategories->cache));
     //If the data are not available from the cache
     if (empty($posts) || empty($paging)) {
         $query = $this->PostsCategories->Posts->find('active')->select(['id', 'title', 'subtitle', 'slug', 'text', 'created'])->contain(['Categories' => function ($q) {
             return $q->select(['id', 'title', 'slug']);
         }, 'Tags' => function ($q) {
             return $q->order(['tag' => 'ASC']);
         }, 'Users' => function ($q) {
             return $q->select(['first_name', 'last_name']);
         }])->where(['Categories.slug' => $slug])->order([sprintf('%s.created', $this->PostsCategories->Posts->alias()) => 'DESC']);
         if ($query->isEmpty()) {
             throw new RecordNotFoundException(__d('me_cms', 'Record not found'));
         }
         $posts = $this->paginate($query)->toArray();
         //Writes on cache
         Cache::writeMany([$cache => $posts, sprintf('%s_paging', $cache) => $this->request->param('paging')], $this->PostsCategories->cache);
         //Else, sets the paging parameter
     } else {
         $this->request->params['paging'] = $paging;
     }
     $this->set(am(['category' => $posts[0]->category], compact('posts')));
 }
开发者ID:mirko-pagliai,项目名称:me-cms,代码行数:38,代码来源:PostsCategoriesController.php

示例2: testReadMany

 /**
  * testReadMany method
  *
  * @return void
  */
 public function testReadMany()
 {
     $this->_configCache(['duration' => 2]);
     $data = ['App.falseTest' => false, 'App.trueTest' => true, 'App.nullTest' => null, 'App.zeroTest' => 0, 'App.zeroTest2' => '0'];
     foreach ($data as $key => $value) {
         Cache::write($key, $value, 'memcached');
     }
     $read = Cache::readMany(array_merge(array_keys($data), ['App.doesNotExist']), 'memcached');
     $this->assertSame($read['App.falseTest'], false);
     $this->assertSame($read['App.trueTest'], true);
     $this->assertSame($read['App.nullTest'], null);
     $this->assertSame($read['App.zeroTest'], 0);
     $this->assertSame($read['App.zeroTest2'], '0');
     $this->assertSame($read['App.doesNotExist'], false);
 }
开发者ID:KarimaLadhani,项目名称:cakephp,代码行数:20,代码来源:MemcachedEngineTest.php

示例3: testDeleteMany

 /**
  * testDeleteMany method
  *
  * @return void
  */
 public function testDeleteMany()
 {
     $this->_configCache();
     $data = array('App.falseTest' => false, 'App.trueTest' => true, 'App.nullTest' => null, 'App.zeroTest' => 0, 'App.zeroTest2' => '0');
     Cache::writeMany(array_merge($data, array('App.keepTest' => 'keepMe')), 'tests');
     Cache::deleteMany(array_keys($data), 'tests');
     $read = Cache::readMany(array_merge(array_keys($data), array('App.keepTest')), 'tests');
     $this->assertSame($read['App.falseTest'], false);
     $this->assertSame($read['App.trueTest'], false);
     $this->assertSame($read['App.nullTest'], false);
     $this->assertSame($read['App.zeroTest'], false);
     $this->assertSame($read['App.zeroTest2'], false);
     $this->assertSame($read['App.keepTest'], 'keepMe');
 }
开发者ID:maitrepylos,项目名称:nazeweb,代码行数:19,代码来源:CacheTest.php

示例4: search

 /**
  * Searches posts
  * @return void
  * @uses MeCms\Controller\AppController::_checkLastSearch()
  */
 public function search()
 {
     $pattern = $this->request->query('p');
     if ($pattern) {
         //Checks if the pattern is at least 4 characters long
         if (strlen($pattern) >= 4) {
             if ($this->_checkLastSearch($pattern)) {
                 $this->paginate['limit'] = config('default.records_for_searches');
                 $page = $this->request->query('page') ? $this->request->query('page') : 1;
                 //Sets the initial cache name
                 $cache = sprintf('search_%s', md5($pattern));
                 //Updates the cache name with the query limit and the number of the page
                 $cache = sprintf('%s_limit_%s', $cache, $this->paginate['limit']);
                 $cache = sprintf('%s_page_%s', $cache, $page);
                 //Tries to get data from the cache
                 list($posts, $paging) = array_values(Cache::readMany([$cache, sprintf('%s_paging', $cache)], $this->Posts->cache));
                 //If the data are not available from the cache
                 if (empty($posts) || empty($paging)) {
                     $query = $this->Posts->find('active')->select(['title', 'slug', 'text', 'created'])->where(['OR' => ['title LIKE' => sprintf('%%%s%%', $pattern), 'subtitle LIKE' => sprintf('%%%s%%', $pattern), 'text LIKE' => sprintf('%%%s%%', $pattern)]])->order([sprintf('%s.created', $this->Posts->alias()) => 'DESC']);
                     $posts = $this->paginate($query)->toArray();
                     //Writes on cache
                     Cache::writeMany([$cache => $posts, sprintf('%s_paging', $cache) => $this->request->param('paging')], $this->Posts->cache);
                     //Else, sets the paging parameter
                 } else {
                     $this->request->params['paging'] = $paging;
                 }
                 $this->set(compact('posts'));
             } else {
                 $this->Flash->alert(__d('me_cms', 'You have to wait {0} seconds to perform a new search', config('security.search_interval')));
             }
         } else {
             $this->Flash->alert(__d('me_cms', 'You have to search at least a word of {0} characters', 4));
         }
     }
     $this->set(compact('pattern'));
 }
开发者ID:mirko-pagliai,项目名称:me-cms,代码行数:41,代码来源:PostsController.php


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