本文整理汇总了PHP中Cake\Cache\Cache::writeMany方法的典型用法代码示例。如果您正苦于以下问题:PHP Cache::writeMany方法的具体用法?PHP Cache::writeMany怎么用?PHP Cache::writeMany使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\Cache\Cache
的用法示例。
在下文中一共展示了Cache::writeMany方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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')));
}
示例2: main
public function main()
{
try {
$DEFAULT_URL = 'https://ens.firebaseio.com/';
$DEFAULT_TOKEN = Configure::read('Firebase.token');
$DEFAULT_PATH = '/call';
$firebase = new \Firebase\FirebaseLib($DEFAULT_URL, $DEFAULT_TOKEN);
if (!isset($this->args[0])) {
throw new \Exception('Missing queue ID');
}
$this->out('Start...');
$sendQueueTable = TableRegistry::get('SendQueues');
$numberTable = TableRegistry::get('Numbers');
$dateTimeUtc = new \DateTimeZone('UTC');
$now = new \DateTime('now', $dateTimeUtc);
$sendQueue = $sendQueueTable->find('all', ['conditions' => ['type' => 2, 'send_queue_id' => $this->args[0], 'OR' => ['next_try_datetime IS NULL', 'next_try_datetime <=' => $now]]]);
if (!$sendQueue->count()) {
throw new \Exception('No more queue');
}
$firstQueue = $sendQueue->first();
// Mark as being processed...
$firebase->set($DEFAULT_PATH . '/' . $firstQueue->send_queue_id . '/status', 1);
$firstQueue->status = 1;
$firstQueue->start_datetime = $now;
$sendQueueTable->save($firstQueue);
$this->out(json_encode($firstQueue));
$numbers = $numberTable->find('all', ['fields' => ['number_id', 'number_list_id', 'country_code', 'phone_number'], 'conditions' => ['number_list_id' => $firstQueue->number_list_id]]);
foreach ($numbers as $number) {
Cache::writeMany();
}
// Format the number for Firebase
$numberForFb = Hash::combine($numbers->toArray(), '{n}.number_id', '{n}');
// Put the all the number on Firebase
$firebase->set($DEFAULT_PATH . '/' . $firstQueue->send_queue_id . '/numbers', $numberForFb);
$this->out(json_encode($numbers));
// Mark as sending...
$firebase->set($DEFAULT_PATH . '/' . $firstQueue->send_queue_id . '/status', 2);
$firstQueue->status = 2;
$sendQueueTable->save($firstQueue);
// Send Call
foreach ($numbers as $number) {
shell_exec(ROOT . DS . 'bin' . DS . 'cake SendCallBackground ' . $firstQueue->send_queue_id . ' ' . $number->number_id . ' ' . $number->country_code . ' ' . $number->phone_number . ' ' . $firstQueue->unique_id . ' > /dev/null 2>/dev/null &');
usleep(100000);
}
// Mark as done...
$firebase->set($DEFAULT_PATH . '/' . $firstQueue->send_queue_id . '/status', 3);
$firstQueue->status = 3;
$firstQueue->end_datetime = new \DateTime('now', $dateTimeUtc);
$sendQueueTable->save($firstQueue);
} catch (\Exception $ex) {
$this->out($ex->getMessage());
}
}
示例3: testWriteMany
/**
* testWriteMany method
*
* @return void
*/
public function testWriteMany()
{
$this->_configCache(['duration' => 2]);
$data = ['App.falseTest' => false, 'App.trueTest' => true, 'App.nullTest' => null, 'App.zeroTest' => 0, 'App.zeroTest2' => '0'];
Cache::writeMany($data, 'memcached');
$this->assertSame(Cache::read('App.falseTest', 'memcached'), false);
$this->assertSame(Cache::read('App.trueTest', 'memcached'), true);
$this->assertSame(Cache::read('App.nullTest', 'memcached'), null);
$this->assertSame(Cache::read('App.zeroTest', 'memcached'), 0);
$this->assertSame(Cache::read('App.zeroTest2', 'memcached'), '0');
}
示例4: 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');
}
示例5: 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'));
}