/** * test case startup * * @return void */ public static function setupBeforeClass() { Cache::enable(); Cache::config('session_test', ['engine' => 'File', 'path' => TMP . 'sessions', 'prefix' => 'session_test']); static::$_sessionBackup = Configure::read('Session'); Configure::write('Session.handler.config', 'session_test'); }
/** * setUp method * * @return void */ public function setUp() { parent::setUp(); Configure::write('Acl.classname', __NAMESPACE__ . '\\CachedDbAclTwoTest'); $this->CachedDb = new CachedDbAclTwoTest(); Cache::config('tests', ['engine' => 'File', 'path' => TMP, 'prefix' => 'test_']); }
public function initialize() { parent::initialize(); /** * Configure the cache for the books index page */ Cache::config('exlibrisBooksIndex', ['className' => 'Apc', 'duration' => '+2 hours', 'propability' => 100, 'prefix' => 'apc_']); }
/** * Setup method * * @return void */ public function setUp() { parent::setUp(); $this->engine = $this->getMock('Cake\\Cache\\CacheEngine'); $this->engine->expects($this->any())->method('init')->will($this->returnValue(true)); Cache::config('queryCache', $this->engine); Cache::enable(); }
/** * setup * * @return void */ public function setUp() { parent::setUp(); TableRegistry::clear(); $this->Articles = TableRegistry::get('Articles'); Cache::config('default', ['className' => 'File', 'path' => CACHE, 'duration' => '+10 days']); Cache::delete('Related.attachedTables'); Cache::delete('Related.indexedTables'); }
/** * Test clearing the cache. * * @return void */ public function testClearCache() { $mock = $this->getMock('Cake\\Cache\\CacheEngine'); $mock->expects($this->once())->method('init')->will($this->returnValue(true)); $mock->expects($this->once())->method('clear')->will($this->returnValue(true)); Cache::config('testing', $mock); $this->configRequest(['headers' => ['Accept' => 'application/json']]); $this->post('/debug_kit/toolbar/clear_cache', ['name' => 'testing']); $this->assertResponseOk(); $this->assertResponseContains('success'); }
/** * CacheStorage constructor. * @param array $config initial configuration */ public function __construct(array $config) { $this->config($config); $_config = $this->config(); $_configName = $_config['cacheConfig']; unset($_config['cacheConfig']); if (Cache::config($_configName)) { Cache::drop($_configName); } Cache::config($_configName, $_config); }
/** * setup method * * @return void */ public function setUp() { parent::setUp(); $this->io = $this->getMock('Cake\\Console\\ConsoleIo'); $this->shell = new OrmCacheShell($this->io); $this->cache = $this->getMock('Cake\\Cache\\CacheEngine'); $this->cache->expects($this->any())->method('init')->will($this->returnValue(true)); Cache::config('orm_cache', $this->cache); $ds = ConnectionManager::get('test'); $ds->cacheMetadata('orm_cache'); }
/** * {@inheritdoc} */ public function startup() { foreach (Config::get('cake_orm.datasources', []) as $name => $dataSource) { ConnectionManager::config($name, $dataSource); } Cache::config(Config::get('cake_orm.cache', [])); if (!is_dir($cakeLogPath = LOG_DIR . DS . 'cake')) { mkdir($cakeLogPath, 0777, true); } Log::config('queries', ['className' => 'File', 'path' => LOG_DIR . DS . 'cake' . DS, 'file' => 'queries.log', 'scopes' => ['queriesLog']]); $this->getEventManager()->addSubscriber(new CakeORMSubscriber()); }
function initialize(Container $container) { parent::initialize($container); $configs = $this->getConfigs(); // 设置数据库 foreach ($configs['datasources'] as $name => $config) { ConnectionManager::config($name, $config); } // 设置缓存 foreach ($configs['cache'] as $name => $config) { Cache::config($name, $config); } }
/** * Renders the login form. * * @return \Cake\Network\Response|null */ public function login() { $this->loadModel('User.Users'); $this->viewBuilder()->layout('login'); if ($this->request->is('post')) { $loginBlocking = plugin('User')->settings('failed_login_attempts') && plugin('User')->settings('failed_login_attempts_block_seconds'); $continue = true; if ($loginBlocking) { Cache::config('users_login', ['duration' => '+' . plugin('User')->settings('failed_login_attempts_block_seconds') . ' seconds', 'path' => CACHE, 'engine' => 'File', 'prefix' => 'qa_', 'groups' => ['acl']]); $cacheName = 'login_failed_' . env('REMOTE_ADDR'); $cache = Cache::read($cacheName, 'users_login'); if ($cache && $cache['attempts'] >= plugin('User')->settings('failed_login_attempts')) { $blockTime = (int) plugin('User')->settings('failed_login_attempts_block_seconds'); $this->Flash->warning(__d('user', 'You have reached the maximum number of login attempts. Try again in {0} minutes.', $blockTime / 60)); $continue = false; } } if ($continue) { $user = $this->Auth->identify(); if ($user) { $this->Auth->setUser($user); if (!empty($user['id'])) { try { $user = $this->Users->get($user['id']); if ($user) { $this->Users->touch($user, 'Users.login'); $this->Users->save($user); } } catch (\Exception $e) { // invalid user } } return $this->redirect($this->Auth->redirectUrl()); } else { if ($loginBlocking && isset($cache) && isset($cacheName)) { $cacheStruct = ['attempts' => 0, 'last_attempt' => 0, 'ip' => '', 'request_log' => []]; $cache = array_merge($cacheStruct, $cache); $cache['attempts'] += 1; $cache['last_attempt'] = time(); $cache['ip'] = env('REMOTE_ADDR'); $cache['request_log'][] = ['data' => $this->request->data, 'time' => time()]; Cache::write($cacheName, $cache, 'users_login'); } $this->Flash->danger(__d('user', 'Username or password is incorrect.')); } } } $user = $this->Users->newEntity(); $this->title(__d('user', 'Login')); $this->set(compact('user')); }
/** * Initialize - install cache spies. * * @return void */ public function initialize() { foreach (Cache::configured() as $name) { $config = Cache::config($name); if ($config['className'] instanceof DebugEngine) { $instance = $config['className']; } else { Cache::drop($name); $instance = new DebugEngine($config); Cache::config($name, $instance); } $this->_instances[$name] = $instance; } }
public function onBootstrap(MvcEvent $e) { /* * pega as configurações */ $config = $e->getApplication()->getServiceManager()->get('Config'); /* * arruma a configuração do cakePHP */ $config['CakePHP']['Cache']['_cake_model_']['duration'] = $config['caches']['Zend\\Cache']['options']['ttl']; $config['CakePHP']['Datasources']['default']['host'] = $config['db']['adapters']['Zend\\Db\\Adapter']['host']; $config['CakePHP']['Datasources']['default']['username'] = $config['db']['adapters']['Zend\\Db\\Adapter']['username']; $config['CakePHP']['Datasources']['default']['password'] = $config['db']['adapters']['Zend\\Db\\Adapter']['password']; $config['CakePHP']['Datasources']['default']['database'] = $config['db']['adapters']['Zend\\Db\\Adapter']['dbname']; /* * seta o namespace padrão do CakePHP (App\Model) */ foreach ($config['CakePHP']['Configure'] as $configKey => $configValue) { Configure::write($configKey, $configValue); } /* * configura o cache do CakePHP */ foreach ($config['CakePHP']['Cache'] as $configKey => $configValue) { $cacheDir = sprintf('%s/%s', ROOT_PATH, $configValue['path']); if (!is_dir($cacheDir)) { @mkdir($cacheDir, 0755, true); } Cache::config($configKey, $configValue); } /* * configura o log do CakePHP */ foreach ($config['CakePHP']['Log'] as $configKey => $configValue) { $logDir = sprintf('%s/%s', ROOT_PATH, $configValue['path']); if (!is_dir($logDir)) { @mkdir($logDir, 0755, true); } Log::config($configKey, $configValue); } /* * setup da conexão com banco de dados no CakePHP */ foreach ($config['CakePHP']['Datasources'] as $configKey => $configValue) { ConnectionManager::config($configKey, $configValue); } }
/** * CurrentConfigShell::main() * * @return void */ public function main() { $this->out('DB default:'); try { $db = ConnectionManager::get('default'); $this->out(print_r($db->config(), true)); } catch (Exception $e) { $this->err($e->getMessage()); } $this->out(''); $this->out('DB test:'); try { $db = ConnectionManager::get('test'); $this->out(print_r($db->config(), true)); } catch (Exception $e) { $this->err($e->getMessage()); } $this->out(''); $this->out('Cache:'); $this->out(print_r(Cache::config('_cake_core_'), true)); }
/** * Test clearing a cache group * * @return void */ public function testGroupClear() { Cache::config('memcached_groups', ['engine' => 'Memcached', 'duration' => 3600, 'groups' => ['group_a', 'group_b']]); $this->assertTrue(Cache::write('test_groups', 'value', 'memcached_groups')); $this->assertTrue(Cache::clearGroup('group_a', 'memcached_groups')); $this->assertFalse(Cache::read('test_groups', 'memcached_groups')); $this->assertTrue(Cache::write('test_groups', 'value2', 'memcached_groups')); $this->assertTrue(Cache::clearGroup('group_b', 'memcached_groups')); $this->assertFalse(Cache::read('test_groups', 'memcached_groups')); }
<?php /** * UnionCMS Core * * This file is part of the of the simple cms based on CakePHP 3. * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. * * @package Core * @license MIT * @copyright MIT License http://www.opensource.org/licenses/mit-license.php * @link https://github.com/UnionCMS/Core * @author Sergey Kalistratov <*****@*****.**> */ use Cake\Cache\Cache; Cache::config('test_cached', ['className' => 'File', 'duration' => '+1 week', 'path' => CACHE . 'query' . DS . 'cache' . DS, 'prefix' => 'cache_', 'groups' => ['cached']]);
* @copyright Copyright (c) Frank Förster (http://frankfoerster.com) * @license http://www.opensource.org/licenses/mit-license.php MIT License */ use Cake\Cache\Cache; use Cake\Core\Configure; use Cake\Core\Plugin; use Cake\Event\EventManager; use Cake\Filesystem\Folder; use Wasabi\Cms\Event\DispatcherListener; use Wasabi\Cms\Event\MenuListener; use Wasabi\Cms\Event\RouteListener; use Wasabi\Cms\Event\ThemeListener; use Wasabi\Cms\View\Module\ModuleManager; try { // Load and apply the Wasabi Core cache config. Configure::load('Wasabi/Cms.cache', 'default'); foreach (Configure::consume('Cache') as $key => $config) { new Folder($config['path'], true, 0775); Cache::config($key, $config); } } catch (\Exception $e) { die($e->getMessage() . "\n"); } // Configure plugin translation paths. Configure::write('App.paths.locales', array_merge(Configure::read('App.paths.locales'), [Plugin::path('Wasabi/Cms') . 'src' . DS . 'Locale' . DS])); // Register module path. ModuleManager::registerModulePath(Plugin::path('Wasabi/Cms') . 'src' . DS . 'View' . DS . 'Module' . DS); EventManager::instance()->on(new RouteListener()); EventManager::instance()->on(new ThemeListener()); EventManager::instance()->on(new DispatcherListener()); EventManager::instance()->on(new MenuListener());
/** * set up * * @return void */ public function setUp() { parent::setUp(); $this->panel = new CachePanel(); Cache::config('debug_kit_test', ['className' => 'Null']); }
/** * test that changing the config name of the cache config works. * * @return void */ public function testReadAndWriteWithCustomCacheConfig() { Configure::write('Session.defaults', 'cache'); Configure::write('Session.handler.engine', __NAMESPACE__ . '\\TestCacheSession'); Configure::write('Session.handler.config', 'session_test'); Cache::config('session_test', ['engine' => 'File', 'prefix' => 'session_test_']); TestCakeSession::init(); TestCakeSession::start(); TestCakeSession::write('SessionTestCase', 'Some value'); $this->assertEquals('Some value', TestCakeSession::read('SessionTestCase')); $id = TestCakeSession::id(); Cache::delete($id, 'session_test'); }
/** * Test that when the cell cache is enabled, the cell action is only invoke the first * time the cell is rendered * * @return void */ public function testCachedRenderSimpleCustomTemplateViewBuilder() { Cache::config('default', ['className' => 'File', 'path' => CACHE]); $cell = $this->View->cell('Articles::customTemplateViewBuilder', [], ['cache' => ['key' => 'celltest']]); $result = $cell->render(); $this->assertEquals(1, $cell->counter); $cell->render(); $this->assertEquals(1, $cell->counter); $this->assertContains('This is the alternate template', $result); Cache::delete('celltest'); Cache::drop('default'); }
/** * Test cached render array config * * @return void */ public function testCachedRenderArrayConfig() { $mock = $this->getMock('Cake\\Cache\\CacheEngine'); $mock->method('init')->will($this->returnValue(true)); $mock->method('read')->will($this->returnValue(false)); $mock->expects($this->once())->method('write')->with('my_key', "dummy\n"); Cache::config('cell', $mock); $cell = $this->View->cell('Articles', [], ['cache' => ['key' => 'my_key', 'config' => 'cell']]); $result = $cell->render(); $this->assertEquals("dummy\n", $result); Cache::drop('cell'); }
/** * Test clearing a cache group * * @return void */ public function testGroupClear() { Cache::config('apc_groups', array('engine' => 'Apc', 'duration' => 0, 'groups' => array('group_a', 'group_b'), 'prefix' => 'test_')); $this->assertTrue(Cache::write('test_groups', 'value', 'apc_groups')); $this->assertTrue(Cache::clearGroup('group_a', 'apc_groups')); $this->assertFalse(Cache::read('test_groups', 'apc_groups')); $this->assertTrue(Cache::write('test_groups', 'value2', 'apc_groups')); $this->assertTrue(Cache::clearGroup('group_b', 'apc_groups')); $this->assertFalse(Cache::read('test_groups', 'apc_groups')); }
<?php /** * Licensed under The GPL-3.0 License * For full copyright and license information, please see the LICENSE.txt * Redistributions of files must retain the above copyright notice. * * @since 2.0.0 * @author Christopher Castro <*****@*****.**> * @link http://www.quickappscms.org * @license http://opensource.org/licenses/gpl-3.0.html GPL-3.0 License */ use Cake\Cache\Cache; /** * Used by EavBehavior. */ Cache::config('eav_table_attrs', ['className' => 'File', 'prefix' => 'eav_attrs_', 'path' => CACHE, 'duration' => '+30 minutes', 'groups' => ['eav']]);
/** * test that store and restore only store/restore the provided data. * * @return void */ public function testStoreAndRestoreWithData() { Cache::enable(); Cache::config('configure', ['className' => 'File', 'path' => TMP . 'tests']); Configure::write('testing', 'value'); Configure::store('store_test', 'configure', ['store_test' => 'one']); Configure::delete('testing'); $this->assertNull(Configure::read('store_test'), 'Calling store with data shouldn\'t modify runtime.'); Configure::restore('store_test', 'configure'); $this->assertEquals('one', Configure::read('store_test')); $this->assertNull(Configure::read('testing'), 'Values that were not stored are not restored.'); Cache::delete('store_test', 'configure'); Cache::drop('configure'); }
/** * Test that clearGroup works with no prefix. * * @return void */ public function testGroupClearNoPrefix() { Cache::config('file_groups', ['className' => 'File', 'duration' => 3600, 'prefix' => '', 'groups' => ['group_a', 'group_b']]); Cache::write('key_1', 'value', 'file_groups'); Cache::write('key_2', 'value', 'file_groups'); Cache::clearGroup('group_a', 'file_groups'); $this->assertFalse(Cache::read('key_1', 'file_groups'), 'Did not delete'); $this->assertFalse(Cache::read('key_2', 'file_groups'), 'Did not delete'); }
/** * testCacheDisable method * * Check that the "Cache.disable" configuration and a change to it * (even after a cache config has been setup) is taken into account. * * @return void */ public function testCacheDisable() { Cache::enable(); Cache::config('test_cache_disable_1', ['engine' => 'File', 'path' => TMP . 'tests']); $this->assertTrue(Cache::write('key_1', 'hello', 'test_cache_disable_1')); $this->assertSame(Cache::read('key_1', 'test_cache_disable_1'), 'hello'); Cache::disable(); $this->assertNull(Cache::write('key_2', 'hello', 'test_cache_disable_1')); $this->assertFalse(Cache::read('key_2', 'test_cache_disable_1')); Cache::enable(); $this->assertTrue(Cache::write('key_3', 'hello', 'test_cache_disable_1')); $this->assertSame('hello', Cache::read('key_3', 'test_cache_disable_1')); Cache::clear(false, 'test_cache_disable_1'); Cache::disable(); Cache::config('test_cache_disable_2', ['engine' => 'File', 'path' => TMP . 'tests']); $this->assertNull(Cache::write('key_4', 'hello', 'test_cache_disable_2')); $this->assertFalse(Cache::read('key_4', 'test_cache_disable_2')); Cache::enable(); $this->assertTrue(Cache::write('key_5', 'hello', 'test_cache_disable_2')); $this->assertSame(Cache::read('key_5', 'test_cache_disable_2'), 'hello'); Cache::disable(); $this->assertNull(Cache::write('key_6', 'hello', 'test_cache_disable_2')); $this->assertFalse(Cache::read('key_6', 'test_cache_disable_2')); Cache::enable(); Cache::clear(false, 'test_cache_disable_2'); }
* This URL is used as the base of all absolute links. * * If you define fullBaseUrl in your config file you can remove this. */ if (!Configure::read('App.fullBaseUrl')) { $s = null; if (env('HTTPS')) { $s = 's'; } $httpHost = env('HTTP_HOST'); if (isset($httpHost)) { Configure::write('App.fullBaseUrl', 'http' . $s . '://' . $httpHost); } unset($httpHost, $s); } Cache::config(Configure::consume('Cache')); ConnectionManager::config(Configure::consume('Datasources')); Email::configTransport(Configure::consume('EmailTransport')); Email::config(Configure::consume('Email')); Log::config(Configure::consume('Log')); Security::salt(Configure::consume('Security.salt')); /** * The default crypto extension in 3.0 is OpenSSL. * If you are migrating from 2.x uncomment this code to * use a more compatible Mcrypt based implementation */ // Security::engine(new \Cake\Utility\Crypto\Mcrypt()); /** * Setup detectors for mobile and tablet. */ Request::addDetector('mobile', function ($request) {
/** * setup * * @return void */ public function setUp() { parent::setUp(); Cache::config(['session_test' => ['engine' => 'File']]); $this->storage = new CacheSession(['config' => 'session_test']); }
$loader = new \Cake\Core\ClassLoader(); $loader->register(); $loader->addNamespace('App', APP); //@codingStandardsIgnoreStart @mkdir(LOGS); @mkdir(SESSIONS); @mkdir(CACHE); @mkdir(CACHE . 'views'); @mkdir(CACHE . 'models'); //@codingStandardsIgnoreEnd require_once CORE_PATH . 'config/bootstrap.php'; date_default_timezone_set('UTC'); mb_internal_encoding('UTF-8'); Configure::write('debug', true); Configure::write('App', ['namespace' => 'App', 'encoding' => 'UTF-8', 'base' => false, 'baseUrl' => false, 'dir' => APP_DIR, 'webroot' => 'webroot', 'wwwRoot' => WWW_ROOT, 'fullBaseUrl' => 'http://localhost', 'imageBaseUrl' => 'img/', 'jsBaseUrl' => 'js/', 'cssBaseUrl' => 'css/', 'paths' => ['plugins' => [TEST_APP . 'Plugin' . DS], 'templates' => [APP . 'Template' . DS], 'locales' => [APP . 'Locale' . DS]]]); Cache::config(['_cake_core_' => ['engine' => 'File', 'prefix' => 'cake_core_', 'serialize' => true], '_cake_model_' => ['engine' => 'File', 'prefix' => 'cake_model_', 'serialize' => true]]); // Ensure default test connection is defined if (!getenv('db_dsn')) { putenv('db_dsn=sqlite:///:memory:'); } ConnectionManager::config('test', ['url' => getenv('db_dsn')]); ConnectionManager::config('test_custom_i18n_datasource', ['url' => getenv('db_dsn')]); Configure::write('Session', ['defaults' => 'php']); Configure::write('EmailTransport', ['default' => ['className' => 'Debug']]); Configure::write('Email', ['default' => ['transport' => 'default', 'from' => 'you@localhost']]); Email::configTransport(Configure::consume('EmailTransport')); Email::config(Configure::consume('Email')); Log::config(['debug' => ['engine' => 'Cake\\Log\\Engine\\FileLog', 'levels' => ['notice', 'info', 'debug'], 'file' => 'debug'], 'error' => ['engine' => 'Cake\\Log\\Engine\\FileLog', 'levels' => ['warning', 'error', 'critical', 'alert', 'emergency'], 'file' => 'error']]); Router::reload(); Cake\Routing\DispatcherFactory::add('Routing'); Cake\Routing\DispatcherFactory::add('ControllerFactory');
/** * Test elementCache method * * @return void */ public function testElementCache() { Cache::drop('test_view'); Cache::config('test_view', ['engine' => 'File', 'duration' => '+1 day', 'path' => CACHE . 'views/', 'prefix' => '']); Cache::clear(false, 'test_view'); $View = $this->PostsController->createView(); $View->elementCache = 'test_view'; $result = $View->element('test_element', [], ['cache' => true]); $expected = 'this is the test element'; $this->assertEquals($expected, $result); $result = Cache::read('element__test_element_cache_callbacks', 'test_view'); $this->assertEquals($expected, $result); $result = $View->element('test_element', ['param' => 'one', 'foo' => 'two'], ['cache' => true]); $this->assertEquals($expected, $result); $result = Cache::read('element__test_element_cache_callbacks_param_foo', 'test_view'); $this->assertEquals($expected, $result); $View->element('test_element', ['param' => 'one', 'foo' => 'two'], ['cache' => ['key' => 'custom_key']]); $result = Cache::read('element_custom_key', 'test_view'); $this->assertEquals($expected, $result); $View->elementCache = 'default'; $View->element('test_element', ['param' => 'one', 'foo' => 'two'], ['cache' => ['config' => 'test_view']]); $result = Cache::read('element__test_element_cache_callbacks_param_foo', 'test_view'); $this->assertEquals($expected, $result); Cache::clear(true, 'test_view'); Cache::drop('test_view'); }