Esempio n. 1
0
 /**
  * Display all cache configurations.
  */
 public function cache()
 {
     $config = array();
     foreach (Cache::configured() as $key) {
         $temp = Cache::config($key);
         $config[$key] = $temp['settings'];
     }
     ksort($config);
     $this->set('configuration', $config);
 }
Esempio n. 2
0
 /**
  * Clears content of cache engines
  *
  * @param mixed any amount of strings - keys of configure cache engines
  * @return array associative array with cleanup results
  * @access public
  */
 function engines()
 {
     $result = array();
     $keys = Cache::configured();
     if ($engines = func_get_args()) {
         $keys = array_intersect($keys, $engines);
     }
     foreach ($keys as $key) {
         $result[$key] = Cache::clear(false, $key);
     }
     return $result;
 }
 /**
  * _setupCache
  *  Differentiate croogo's cache prefix so that sites have their own cache
  *  List of cache names are from croogo_bootstrap.php
  */
 public function _setupCache(Controller $controller)
 {
     $configured = Cache::configured();
     $croogoCacheNames = array('croogo_blocks', 'croogo_menus', 'croogo_nodes', 'croogo_types', 'croogo_vocabularies', 'croogo_vocabularies', 'nodes_promoted', 'nodes_term', 'nodes_index', 'contacts_view');
     $siteTitle = Inflector::slug(strtolower(Configure::read('Site.title')));
     for ($i = 0, $ii = count($configured); $i < $ii; $i++) {
         if (!in_array($configured[$i], $croogoCacheNames)) {
             continue;
         }
         $cacheName = $configured[$i];
         $setting = Cache::settings($cacheName);
         $setting = Set::merge($setting, array('prefix' => 'cake_' . $siteTitle . '_'));
         Cache::config($cacheName, $setting);
     }
 }
Esempio n. 4
0
 /**
  * Run the task
  *
  * @return void
  */
 public function execute()
 {
     // @todo Implement cache "type" clearing, so you can clear just models, and leave cached views untouched.
     // $type = 'all';
     // if (!empty($this->args)) {
     // 	$type = $this->args[0];
     // }
     foreach (Cache::configured() as $name) {
         $config = Cache::config($name);
         if (Cache::clear(false, $name)) {
             $this->out('- Cleared ' . $name);
         } else {
             $this->out('! Failed clearing ' . $name);
         }
     }
 }
Esempio n. 5
0
 /**
  * Constructor
  *
  * @param array $settings Array of settings.
  * @return void
  */
 public function __construct($settings)
 {
     parent::__construct();
     $this->title = __d('clear_cache', 'Clear Cache');
     foreach (glob(CACHE . '*', GLOB_ONLYDIR) as $folder) {
         $length = strrpos($folder, DS) + 1;
         $this->folders[] = substr($folder, $length);
     }
     $configured = array_diff(Cache::configured(), array('debug_kit'));
     $this->engines = array_merge($this->engines, $configured);
     foreach (array('folders', 'engines') as $property) {
         if (isset($settings['clear_cache'][$property])) {
             $this->{$property} = (array) $settings['clear_cache'][$property];
         }
     }
 }
Esempio n. 6
0
 public function delete()
 {
     $this->autoRender = false;
     if ($this->params['[method]'] !== 'DELETE') {
         $this->cakeError('error404');
     }
     $configured = Cache::configured();
     if (!in_array($this->params['config'], $configured)) {
         $this->cakeError('error404');
     }
     if (empty($this->params['key'])) {
         Cache::clear(false, $this->params['config']);
     } else {
         Cache::delete($this->params['key'], $this->params['config']);
     }
 }
 /**
  * Clear cache
  */
 protected function _clearCache()
 {
     if ($this->args[0] === 'all') {
         $cacheNames = Cache::configured();
     } else {
         $cacheNames = array_map('trim', explode(',', $this->args[0]));
     }
     foreach ($cacheNames as $cacheName) {
         $success = Cache::clear(false, $cacheName);
         if ($success) {
             $this->out("Cache: {$cacheName} cleared");
         } else {
             $this->err("Cache: {$cacheName} NOT cleared!");
         }
     }
 }
Esempio n. 8
0
File: cache.php Progetto: sams/cache
 /**
  * Delete cache
  *
  * @return void
  * @access protected
  */
 function delete()
 {
     if (empty($this->args) || count($this->args) > 2) {
         $this->help();
         return $this->_stop();
     }
     $configured = Cache::configured();
     if (!in_array($this->args[0], $configured)) {
         $this->err(sprintf(__d('cache', 'Configuration "%s" not found.', true), $this->args[0]));
         return $this->_stop();
     }
     if (isset($this->args[1])) {
         Cache::delete($this->args[1], $this->args[0]);
     } else {
         Cache::clear(false, $this->args[0]);
     }
 }
Esempio n. 9
0
 /**
  * Clears content of cache engines
  *
  * @param mixed any amount of strings - keys of configure cache engines
  * @return array associative array with cleanup results
  */
 public function engines()
 {
     if ($cacheDisabled = (bool) Configure::read('Cache.disable')) {
         Configure::write('Cache.disable', false);
     }
     $result = array();
     $keys = Cache::configured();
     if ($engines = func_get_args()) {
         $keys = array_intersect($keys, $engines);
     }
     foreach ($keys as $key) {
         $result[$key] = Cache::clear(false, $key);
     }
     if ($cacheDisabled) {
         Configure::write('Cache.disable', $cacheDisabled);
     }
     return $result;
 }
 /**
  * Test cache clear task
  * 
  * @param string $cacheNames
  * 
  * @dataProvider clearProvider
  */
 public function testClear($cacheNames)
 {
     $cacheKey = 'CacheShellTest';
     $caches = array_map('trim', explode(',', $cacheNames));
     if ($caches[0] === 'all') {
         $caches = Cache::configured();
     }
     foreach ($caches as $cache) {
         Cache::write($cacheKey, true, $cache);
         $this->assertTrue(Cache::read($cacheKey, $cache));
     }
     $this->Shell->startup();
     $this->Shell->initialize();
     $this->Shell->runCommand('clear', array('clear', $cacheNames));
     foreach ($caches as $cache) {
         $this->assertFalse(Cache::read($cacheKey, $cache));
     }
     debug($this->out);
 }
Esempio n. 11
0
 /**
  * Clear cache task
  */
 public function clear()
 {
     $force = empty($this->params['force']) ? false : true;
     $clearSession = empty($this->params['clear-session']) ? false : true;
     $configs = Cache::configured();
     foreach ($configs as $config) {
         if ('_cache_session_' == $config && !$clearSession) {
             continue;
         }
         if ($force) {
             Cache::clear(false, $config);
         } else {
             $prompt = __d('cake_console', 'Are you want clear cache of config %s ?', $config);
             if ('y' == $this->in($prompt, array('y', 'n'), 'y')) {
                 $cleared = Cache::clear(false, $config);
                 if ($cleared) {
                     $this->out(__d('cake_console', 'Cleared success cache of config %s', $config));
                 } else {
                     $this->out(__d('cake_console', 'Cleared failture cache of config %s', $config));
                 }
             }
         }
     }
 }
Esempio n. 12
0
 /**
  * Removes record for given ID. If no ID is given, the current ID is used. Returns true on success.
  *
  * @param int|string $id ID of record to delete
  * @param bool $cascade Set to true to delete records that depend on this record
  * @return bool True on success
  * @triggers Model.beforeDelete $this, array($cascade)
  * @triggers Model.afterDelete $this
  * @link http://book.cakephp.org/2.0/en/models/deleting-data.html
  */
 public function delete($id = null, $cascade = true)
 {
     /**
      * Returns an array containing the currently configured Cache settings.
      *
      * @return array Array of configured Cache config names.
      */
     $cacheConfigNames = Cache::configured();
     foreach ($cacheConfigNames as $name) {
         /**
          * Delete all keys from the cache.
          *
          * @param boolean $check if true will check expiration, otherwise delete all
          * @param string $config name of the configuration to use. Defaults to 'default'
          * @return boolean True if the cache was successfully cleared, false otherwise
          */
         if (Cache::clear(false, $name)) {
             continue;
         } else {
             return false;
         }
     }
     return true;
 }
 /**
  * test that configured returns an array of the currently configured cache
  * settings
  *
  * @return void
  */
 public function testConfigured()
 {
     $result = Cache::configured();
     $this->assertTrue(in_array('_cake_core_', $result));
     $this->assertTrue(in_array('default', $result));
 }
 /**
  * Clear all caches present related to models
  *
  * Before the 'after' callback method be called is needed to clear all caches.
  * Without it any model operations will use cached data instead of real/modified
  * data.
  *
  * @return void
  */
 protected function _clearCache()
 {
     // Clear the cache
     DboSource::$methodCache = array();
     $keys = Cache::configured();
     foreach ($keys as $key) {
         Cache::clear(false, $key);
     }
     ClassRegistry::flush();
     // Refresh the model, in case something changed
     if ($this->Version instanceof MigrationVersion) {
         $this->Version->initVersion();
     }
 }
Esempio n. 15
0
 /**
  * Get/Set caching.
  *
  * @param null|boolean|string $cache Cache config name to use, If true is passed, 'cake_pdf' will be used.
  * @return mixed
  */
 public function cache($cache = null)
 {
     if ($cache === null) {
         return $this->_cache;
     }
     if ($cache === false) {
         $this->_cache = false;
         return $this;
     }
     if ($cache === true) {
         $cache = 'cake_pdf';
     }
     if (!in_array($cache, Cache::configured())) {
         throw new CakeException(sprintf('CakePdf cache is not configured: %s', $cache));
     }
     $this->_cache = $cache;
     return $this;
 }
Esempio n. 16
0
 protected function _clearCache()
 {
     DboSource::$methodCache = array();
     $keys = Cache::configured();
     foreach ($keys as $key) {
         Cache::clear(false, $key);
     }
     ClassRegistry::flush();
 }
Esempio n. 17
0
 /**
  * Get list of groups with their associated cache configurations
  *
  * @return array
  */
 public static function getGroups()
 {
     $groups = array();
     $keys = Cache::configured();
     foreach ($keys as $key) {
         $config = Cache::config($key);
         if (!empty($config['settings']['groups'])) {
             foreach ($config['settings']['groups'] as $group) {
                 if (!isset($groups[$group])) {
                     $groups[$group] = array();
                 }
                 if (!in_array($key, $groups[$group])) {
                     $groups[$group][] = $key;
                 }
             }
         }
     }
     return $groups;
 }
Esempio n. 18
0
 /**
  * Clear all caches present related to models
  *
  * Before the 'after' callback method be called is needed to clear all caches.
  * Without it any model operations will use cached data instead of real/modified
  * data.
  *
  * @return void
  */
 protected function _clearCache()
 {
     // Clear the cache
     DboSource::$methodCache = array();
     $keys = Cache::configured();
     foreach ($keys as $key) {
         Cache::clear(false, $key);
     }
     ClassRegistry::flush();
     // Refresh the model, in case something changed
     $options = array('class' => 'Migrations.SchemaMigration', 'ds' => $this->connection);
     $this->Version->Version =& ClassRegistry::init($options);
     $this->Version->Version->setDataSource($this->connection);
 }
Esempio n. 19
0
 /**
  * @brief Delete all cahce for the plugin.
  *
  * Will automaticaly delete all the cache for a model that it can detect.
  * you can overlaod after save/delete to stop this happening if you dont
  * want all your cache rebuilt after a save/delete.
  *
  * @todo should use the clear_cache plugin for this
  *
  * @access private
  *
  * @return void
  */
 private function __clearCache()
 {
     if (in_array($this->plugin, Cache::configured())) {
         $_cache = Cache::getInstance()->__config[$this->plugin];
         $path = CACHE . str_replace('.', DS, $_cache['prefix']);
         if (CACHE !== $path && is_dir($path)) {
             $Folder = new Folder($path);
             if ($Folder->delete()) {
                 $this->log('deleted: ' . $path, 'cache_clearing');
             } else {
                 $this->log('failed: ' . $path, 'cache_clearing');
             }
         } else {
             $this->log('skip: ' . $path, 'cache_clearing');
         }
     }
 }
Esempio n. 20
0
 /**
  * {@inheritdoc}
  */
 public function getOptionParser()
 {
     return ConsoleOptionParser::buildFromArray(array('command' => 'clear_cache', 'description' => array(__d('webmaster', "Clear application's cache")), 'options' => array('expired' => array('help' => __d('webmaster', 'Cache configuration to use in conjunction with `toolkit clear`.'), 'short' => 'e', 'boolean' => true, 'default' => false), 'config' => array('help' => __d('webmaster', "Specify the cache configuration's name."), 'short' => 'c', 'choices' => Cache::configured()))));
 }
Esempio n. 21
0
 /**
  * Inits slugger cache if it's not set up
  */
 public function __construct()
 {
     if (!in_array(self::$_config, Cache::configured())) {
         Cache::config('Slugger', array('engine' => 'File', 'duration' => '+1 days', 'prefix' => 'slugger_'));
     }
 }