本文整理汇总了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);
}
示例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'));
}
示例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;
}
示例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;
}
示例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>
}
示例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');
}
示例7: read
public function read($id)
{
$result = Cache::read($id, $this->cacheKey);
if ($result) {
return $result;
}
return parent::read($id);
}
示例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;
}
示例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;
}
示例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']);
}
示例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);
}
示例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;
}
示例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'));
}
示例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);
}
示例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);
}