本文整理汇总了PHP中Cake\Cache\Cache类的典型用法代码示例。如果您正苦于以下问题:PHP Cache类的具体用法?PHP Cache怎么用?PHP Cache使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Cache类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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');
}
示例3: 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>
}
示例4: tearDown
/**
* Teardown
*
* @return void
*/
public function tearDown()
{
parent::tearDown();
Cache::drop('orm_cache');
$ds = ConnectionManager::get('test');
$ds->cacheMetadata(false);
}
示例5: listPrefixes
/**
* Show a list of all defined cache prefixes.
*
* @return void
*/
public function listPrefixes()
{
$prefixes = Cache::configured();
foreach ($prefixes as $prefix) {
$this->out($prefix);
}
}
示例6: _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;
}
示例7: setUp
/**
* Setup
*
* @return void
*/
public function setUp()
{
parent::setUp();
Cache::clear(false);
$this->apiFolderName = 'NonExistingApiPrefixedFolder';
$this->apiFolderPath = APP . 'Controller' . DS . $this->apiFolderName;
}
示例8: 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;
}
示例9: main
/**
* Execute the ClearCache task.
*
* @return void
*/
public function main()
{
Cache::clear(false, '_cake_core_');
Cache::clear(false, 'database');
Cache::clear(false, 'acl');
$this->out('<info>The</info> "<error>deployer clear_cache</error>" <info>command has been executed successfully !</info>', 2);
}
示例10: _clearCacheGroup
/**
* Clear cache group.
*
* @return void
*/
protected function _clearCacheGroup()
{
$cacheGroups = $this->config('groups');
foreach ($cacheGroups as $group) {
Cache::clearGroup($group, $this->config('config'));
}
}
示例11: _touch
protected function _touch(Request $request)
{
$key = $this->config('identifier');
if (is_callable($key)) {
$key = $key($request);
}
return Cache::increment($key, static::$cacheConfig);
}
示例12: tearDown
/**
* Tear down data.
*
* @return void
*/
public function tearDown()
{
parent::tearDown();
Plugin::unload($this->plugin);
Cache::drop('permissions');
Cache::drop('permission_roles');
unset($this->Roles, $this->Users, $this->userData);
}
示例13: main
public function main()
{
if (Cache::clear(false)) {
$this->success('Cake cache clear complete');
} else {
$this->err("Error : Cake cache clear failed");
}
}
示例14: cleanup
/**
* Clears the cache
*
* @return void
*/
public function cleanup()
{
Cache::clear(false, 'default');
Cache::clear(false, '_cake_model_');
Cache::clear(false, '_cake_core_');
$this->dispatchShell('orm_cache clear');
$this->dispatchShell('orm_cache build');
}
示例15: startup
/**
* Assign $this->connection to the active task if a connection param is set.
*
* @return void
*/
public function startup()
{
parent::startup();
Configure::write('debug', true);
Cache::disable();
if (isset($this->params['connection'])) {
$this->connection = $this->params['connection'];
}
}