/** * Check that no fatal errors are issued doing normal things when Cache.disable is true. * * @return void */ public function testNonFatalErrorsWithCacheDisable() { Cache::disable(); $this->_configCache(); $this->assertNull(Cache::write('no_save', 'Noooo!', 'tests')); $this->assertFalse(Cache::read('no_save', 'tests')); $this->assertNull(Cache::delete('no_save', 'tests')); }
/** * Check that no fatal errors are issued doing normal things when Cache.disable is true. * * @return void */ public function testNonFatalErrorsWithCachedisable() { Cache::disable(); $this->_configCache(); Cache::write('no_save', 'Noooo!', 'tests'); Cache::read('no_save', 'tests'); Cache::delete('no_save', 'tests'); }
/** * 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'); }
/** * 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); }
/** * 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); }
/** * Loads a plugin and optionally loads bootstrapping and routing files. * * This method is identical to CakePlugin::load() with extra functionality * that loads event configuration when Plugin/Config/events.php is present. * * @see CakePlugin::load() * @param mixed $plugin name of plugin, or array of plugin and its config * @return void */ public static function load($plugin, $config = []) { Plugin::load($plugin, $config); if (is_string($plugin)) { $plugin = [$plugin => $config]; } Cache::delete('EventHandlers', 'default'); foreach ($plugin as $name => $conf) { list($name, $conf) = is_numeric($name) ? [$conf, $config] : [$name, $conf]; Hook::applyHookConfigFiles('Hook.config_files', $name); } }
protected function clear($alias, array $params = []) { $params += ['config' => true, 'cache' => true]; if (true === $params['config']) { $key = $this->Items->behaviors()->get($alias)->cacheKey(); Cache::delete($key); } if (true === $params['cache']) { $behavior = $this->Items->behaviors()->get($alias); $key = ConfigureKey::fqn($behavior); Configure::write($key, null); } }
/** * Tests the getTypes method * * @return void * @covers ::getTypes */ public function testGetTypes() { Cache::delete('database_log_types'); $this->Logs->deleteAll('1=1'); $data = ['type' => 'Foo', 'message' => 'some text']; $log = $this->Logs->newEntity($data); $res = $this->Logs->save($log); $this->assertTrue(!empty($res)); $data = ['type' => 'Bar', 'message' => 'some more text']; $log = $this->Logs->newEntity($data); $res = $this->Logs->save($log); $this->assertTrue(!empty($res)); $res = $this->Logs->getTypes(); $this->assertSame(['Bar', 'Foo'], $res); }
/** * Callback for Helper::beforeLayout * * @param Event $view Event * @param string $layoutFile layout file name * * @return bool true */ public function beforeLayout(Event $event, $layoutFile) { if (!Cache::enabled()) { $this->config('disable', true); } elseif (!$this->request->is('get')) { $this->config('disable', true); } elseif ($this->request->session()->check('Flash')) { $this->config('disable', true); } elseif ($this->_View->get(ViewMemcachedHelper::NOCACHE)) { $this->config('disable', true); } if ($this->_View->get(ViewMemcachedHelper::DELETE) === true) { Cache::delete($this->config('cacheKey'), $this->config('cacheConfig')); } return true; }
/** * Edit a setting. * * @return \Cake\Network\Response|void */ public function edit() { $setting = $this->Settings->find()->where(['Settings.id' => $this->request->id])->first(); if (is_null($setting)) { $this->Flash->error(__d('admin', 'This setting doesn\'t exist or has been deleted.')); return $this->redirect(['action' => 'index']); } if ($this->request->is(['post', 'put'])) { $this->Settings->patchEntity($setting, $this->request->data); $setting->last_updated_user_id = $this->Auth->user('id'); if ($this->Settings->save($setting)) { Cache::delete('settings', 'database'); $this->Flash->success(__d('admin', 'This setting has been edited successfully !')); return $this->redirect(['action' => 'index']); } } $this->set(compact('setting')); }
/** * Clear metadata. * * @param string|null $name The name of the table to clear cache data for. * @return bool */ public function clear($name = null) { $schema = $this->_getSchema(); if (!$schema) { return false; } $tables = [$name]; if (empty($name)) { $tables = $schema->listTables(); } $configName = $schema->cacheMetadata(); foreach ($tables as $table) { $this->_io->verbose(sprintf('Clearing metadata cache from "%s" for %s', $configName, $table)); $key = $schema->cacheKey($table); Cache::delete($key, $configName); } $this->out('<success>Cache clear complete</success>'); return true; }
protected function execute(InputInterface $input, OutputInterface $output) { $schema = $this->_getSchema($input, $output); $name = $input->getArgument('name'); if (!$schema) { return false; } $tables = [$name]; if (empty($name)) { $tables = $schema->listTables(); } $configName = $schema->cacheMetadata(); foreach ($tables as $table) { $output->writeln(sprintf('Clearing metadata cache from "%s" for %s', $configName, $table)); $key = $schema->cacheKey($table); Cache::delete($key, $configName); } $output->writeln('<info>Cache clear complete<info>'); return true; }
/** * Test add * * @return void */ public function testAdd() { Cache::delete('test_add_key', 'memcached'); $result = Cache::add('test_add_key', 'test data', 'memcached'); $this->assertTrue($result); $expected = 'test data'; $result = Cache::read('test_add_key', 'memcached'); $this->assertEquals($expected, $result); $result = Cache::add('test_add_key', 'test data 2', 'memcached'); $this->assertFalse($result); }
/** * {@inheritDoc} */ protected function doDelete($id) { return Cache::delete($id, $this->config); }
/** * testViewVarNocache method * * @return void */ public function testViewVarNocache() { $this->helper->config('gzipCompress', false); $cacheConfig = $this->helper->config('cacheConfig'); $cacheKey = $this->helper->config('cacheKey'); Cache::delete($cacheKey, $cacheConfig); $this->View->set(ViewMemcachedHelper::NOCACHE, true); $this->View->set('test', 'nocache'); $content = $this->View->render('home', 'default'); $cache = Cache::read($cacheKey, $cacheConfig); $this->assertTrue($cache === false); }
public function afterDelete() { Cache::delete('NavInfos', 'long'); }
/** * @param string $identifier unique string identifier to store associated data * @return bool */ public function delete($identifier) { return Cache::delete($identifier, $this->_config['cacheConfig']); }
/** * Method called on the destruction of a cache session. * * @param int $id ID that uniquely identifies session in cache * @return bool True for successful delete, false otherwise. */ public function destroy($id) { return Cache::delete($id, $this->_options['config']); }
/** * Cache::delete */ public function afterSave() { Cache::delete('custom_config', 'long'); }
/** * Parse ini file and returns the allowed roles per action. * * Uses cache for maximum performance. * Improved speed by several actions before caching: * - Resolves role slugs to their primary key / identifier * - Resolves wildcards to their verbose translation * * @param string|null $path * @return array Roles */ protected function _getAcl($path = null) { if ($path === null) { $path = ROOT . DS . 'config' . DS; } if ($this->_config['autoClearCache'] && Configure::read('debug')) { Cache::delete($this->_config['cacheKey'], $this->_config['cache']); } $roles = Cache::read($this->_config['cacheKey'], $this->_config['cache']); if ($roles !== false) { return $roles; } $iniArray = $this->_parseAclIni($path . ACL_FILE); $availableRoles = $this->_getAvailableRoles(); $res = []; foreach ($iniArray as $key => $array) { $res[$key] = $this->_deconstructIniKey($key); $res[$key]['map'] = $array; foreach ($array as $actions => $roles) { // Get all roles used in the current ini section $roles = explode(',', $roles); $actions = explode(',', $actions); foreach ($roles as $roleId => $role) { if (!($role = trim($role))) { continue; } // Prevent undefined roles appearing in the iniMap if (!array_key_exists($role, $availableRoles) && $role !== '*') { unset($roles[$roleId]); continue; } if ($role === '*') { unset($roles[$roleId]); $roles = array_merge($roles, array_keys($availableRoles)); } } foreach ($actions as $action) { $action = trim($action); if (!$action) { continue; } foreach ($roles as $role) { $role = trim($role); if (!$role || $role === '*') { continue; } // Lookup role id by name in roles array $newRole = $availableRoles[strtolower($role)]; $res[$key]['actions'][$action][] = $newRole; } } } } Cache::write($this->_config['cacheKey'], $res, $this->_config['cache']); return $res; }
/** * 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'); }
/** * Get cache key. * * @param Entity $entity * @return string */ private function __deleteMenuLinksCache(Entity $entity) { $cacheKey = 'menu_' . $entity->get('menu_id') . '_links'; Cache::delete($cacheKey, 'menu_links'); }
public function destroy($id) { Cache::delete($id, $this->cacheKey); return parent::destroy($id); }
/** * {@inheritDoc} */ public function afterSave(Field $field) { $entity = $field->get('metadata')->get('entity'); $table = TableRegistry::get($entity->source()); $pk = $table->primaryKey(); if ($entity->has($pk)) { $TermsCache = TableRegistry::get('Taxonomy.EntitiesTerms'); $tableAlias = Inflector::underscore($table->alias()); $extra = !is_array($field->extra) ? [$field->extra] : $field->extra; $TermsCache->deleteAll(['entity_id' => $entity->get($pk), 'table_alias' => $tableAlias, 'field_instance_id' => $field->metadata->instance_id]); foreach ($extra as $termId) { Cache::delete("t{$termId}", 'terms_count'); $cacheEntity = $TermsCache->newEntity(['entity_id' => $entity->get($pk), 'term_id' => $termId, 'table_alias' => $tableAlias, 'field_instance_id' => $field->metadata->instance_id]); $TermsCache->save($cacheEntity); } } }
/** * Tests that deleteing from a groups-enabled config is possible * * @return void */ public function testGroupDelete() { 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->assertEquals('value', Cache::read('test_groups', 'apc_groups')); $this->assertTrue(Cache::delete('test_groups', 'apc_groups')); $this->assertFalse(Cache::read('test_groups', 'apc_groups')); }
/** * Tests that deleteing from a groups-enabled config is possible * * @return void */ public function testGroupDelete() { Cache::config('wincache_groups', ['engine' => 'Wincache', 'duration' => 0, 'groups' => ['group_a', 'group_b'], 'prefix' => 'test_']); $this->assertTrue(Cache::write('test_groups', 'value', 'wincache_groups')); $this->assertEquals('value', Cache::read('test_groups', 'wincache_groups')); $this->assertTrue(Cache::delete('test_groups', 'wincache_groups')); $this->assertFalse(Cache::read('test_groups', 'wincache_groups')); }
/** * 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'); }
/** * Called after an entity is saved. * * @param Event $event An event instance. * @param Setting $entity The entity that triggered the event. * @param ArrayObject $options Additional options passed to the save call. * @return void */ public function afterSave(Event $event, Setting $entity, ArrayObject $options) { Cache::delete('settings', 'wasabi/core/longterm'); $this->eventManager()->dispatch(new Event('Wasabi.Settings.changed')); }
/** * Tests that deleteing from a groups-enabled config is possible * * @return void */ public function testGroupDelete() { Cache::config('memcached_groups', ['engine' => 'Memcached', 'duration' => 3600, 'groups' => ['group_a', 'group_b']]); $this->assertTrue(Cache::write('test_groups', 'value', 'memcached_groups')); $this->assertEquals('value', Cache::read('test_groups', 'memcached_groups')); $this->assertTrue(Cache::delete('test_groups', 'memcached_groups')); $this->assertFalse(Cache::read('test_groups', 'memcached_groups')); }
/** * 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'); }