本文整理汇总了PHP中Cake\Cache\Cache::engine方法的典型用法代码示例。如果您正苦于以下问题:PHP Cache::engine方法的具体用法?PHP Cache::engine怎么用?PHP Cache::engine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\Cache\Cache
的用法示例。
在下文中一共展示了Cache::engine方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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'));
}
示例2: testConfig
/**
* testConfig method
*
* @return void
*/
public function testConfig()
{
$config = Cache::engine('xcache')->config();
$expecting = ['prefix' => 'cake_', 'duration' => 3600, 'probability' => 100];
$this->assertTrue(isset($config['PHP_AUTH_USER']));
$this->assertTrue(isset($config['PHP_AUTH_PW']));
unset($config['PHP_AUTH_USER'], $config['PHP_AUTH_PW']);
$this->assertEquals($config, $expecting);
}
示例3: testInitializeTwiceNoDoubleProxy
/**
* Ensure that subrequests don't double proxy the cache engine.
*
* @return void
*/
public function testInitializeTwiceNoDoubleProxy()
{
$event = new Event('Sample');
$this->panel->initialize($event);
$result = Cache::engine('debug_kit_test');
$this->assertInstanceOf('DebugKit\\Cache\\Engine\\DebugEngine', $result);
$this->panel->initialize($event);
$result2 = Cache::engine('debug_kit_test');
$this->assertSame($result2, $result);
}
示例4: translators
/**
* Returns the translators collection instance. It can be used
* for getting specific translators based of their name and locale
* or to configure some aspect of future translations that are not yet constructed.
*
* @return \Aura\Intl\TranslatorLocator The translators collection.
*/
public static function translators()
{
if (static::$_collection !== null) {
return static::$_collection;
}
static::$_collection = new TranslatorRegistry(new PackageLocator(), new FormatterLocator(['sprintf' => function () {
return new SprintfFormatter();
}, 'default' => function () {
return new IcuFormatter();
}]), new TranslatorFactory(), static::locale());
if (class_exists('Cake\\Cache\\Cache')) {
static::$_collection->setCacher(Cache::engine('_cake_core_'));
}
return static::$_collection;
}
示例5: clear
/**
* Clear metadata.
*
* @param string|null $prefix The cache prefix to be cleared.
* @throws \Cake\Console\Exception\StopException
* @return void
*/
public function clear($prefix = null)
{
try {
$engine = Cache::engine($prefix);
Cache::clear(false, $prefix);
if ($engine instanceof ApcEngine) {
$this->warn("ApcEngine detected: Cleared {$prefix} CLI cache successfully " . "but {$prefix} web cache must be cleared separately.");
} elseif ($engine instanceof WincacheEngine) {
$this->warn("WincacheEngine detected: Cleared {$prefix} CLI cache successfully " . "but {$prefix} web cache must be cleared separately.");
} else {
$this->out("<success>Cleared {$prefix} cache</success>");
}
} catch (\InvalidArgumentException $e) {
$this->abort($e->getMessage());
}
}
示例6: testConfig
/**
* testConfig method
*
* @return void
*/
public function testConfig()
{
$config = Cache::engine('memcached')->config();
unset($config['path']);
$expecting = ['prefix' => 'cake_', 'duration' => 3600, 'probability' => 100, 'servers' => ['127.0.0.1'], 'persistent' => false, 'compress' => false, 'username' => null, 'password' => null, 'groups' => [], 'serialize' => 'php', 'options' => [], 'host' => null, 'port' => null];
$this->assertEquals($expecting, $config);
}
示例7: _resolveCacher
/**
* Get the cache engine.
*
* @return \Cake\Cache\CacheEngine
*/
protected function _resolveCacher()
{
if (is_string($this->_config)) {
return Cache::engine($this->_config);
}
return $this->_config;
}
示例8: testConnect
/**
* testConnect method
*
* @return void
*/
public function testConnect()
{
$Redis = new RedisEngine();
$this->assertTrue($Redis->init(Cache::engine('redis')->config()));
}
示例9: testDrop
/**
* test that drop removes cache configs, and that further attempts to use that config
* do not work.
*
* @return void
*/
public function testDrop()
{
Configure::write('App.namespace', 'TestApp');
$result = Cache::drop('some_config_that_does_not_exist');
$this->assertFalse($result, 'Drop should not succeed when config is missing.');
Cache::config('unconfigTest', ['engine' => 'TestAppCache']);
$this->assertInstanceOf('TestApp\\Cache\\Engine\\TestAppCacheEngine', Cache::engine('unconfigTest'));
$this->assertTrue(Cache::drop('unconfigTest'));
}
示例10: testConfig
/**
* testConfig method
*
* @return void
*/
public function testConfig()
{
$config = Cache::engine('memcached')->config();
unset($config['path']);
$expecting = array('prefix' => 'cake_', 'duration' => 3600, 'probability' => 100, 'servers' => array('127.0.0.1'), 'persistent' => false, 'compress' => false, 'login' => null, 'password' => null, 'groups' => array(), 'serialize' => 'php');
$this->assertEquals($expecting, $config);
}
示例11: __construct
/**
* Constructor
*
* @param string $alias Cache name alias.
*/
public function __construct($alias)
{
$this->_engine = Cache::engine($alias);
}