Esempio n. 1
0
 /**
  * キャッシュの初期設定をチェックする
  *
  * @param string $name 		キャッシュ名
  * @param string $prefix 	接頭語
  * @param string $path 		ディレクトリパス
  * @param string $duration	キャッシュ時間
  * @dataProvider getCacheSettingDataProvider
  */
 public function testCacheSettings($name, $prefix, $path, $duration)
 {
     $config = Cache::config($name);
     $this->assertEquals($prefix, $config['settings']['prefix']);
     $this->assertEquals($duration, $config['settings']['duration']);
     $this->assertTrue(strpos($config['settings']['path'], $path) === 0);
 }
Esempio n. 2
0
 /**
  * testTranslationCaching method
  *
  * @return void
  */
 public function testTranslationCaching()
 {
     Configure::write('Config.language', 'cache_test_po');
     // reset internally stored entries
     I18n::clear();
     Cache::clear(false, '_cake_core_');
     $lang = Configure::read('Config.language');
     Cache::config('_cake_core_', Cache::config('default'));
     // 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'));
 }
Esempio n. 3
0
 /**
  * Configure a cache engine
  *
  * @param string $name Name of the Cache engine
  * @param array $settings Additional settings to merge into \defaultCacheSettings
  * @return void
  */
 public static function configureCache($name, $settings = array())
 {
     $settings = array_merge(array('duration' => static::getCacheTimeout(), 'prefix' => basename(dirname(dirname(APP)))), static::$defaultCacheSettings, Configure::read('RedisCache.cache'), $settings);
     $settings['prefix'] .= '.' . str_replace('_', '.', $name) . '.';
     $settings['prefix'] = str_replace('..', '.', $settings['prefix']);
     Cache::config($name, $settings);
 }
/**
 * start a test
 *
 * @return void
 */
	public function setUp() {
		parent::setUp();
		$this->_pluginPath = App::pluginPath('AssetCompress');
		$this->_testFiles = $this->_pluginPath . 'Test' . DS . 'test_files' . DS;
		$testFile = $this->_testFiles . 'Config' . DS . 'config.ini';

		AssetConfig::clearAllCachedKeys();

		Cache::drop(AssetConfig::CACHE_CONFIG);
		Cache::config(AssetConfig::CACHE_CONFIG, array(
			'path' => TMP,
			'prefix' => 'asset_compress_test_',
			'engine' => 'File'
		));

		$controller = null;
		$request = new CakeRequest(null, false);
		$request->webroot = '';
		$view = new View($controller);
		$view->request = $request;
		$this->Helper = new AssetCompressHelper($view, array('noconfig' => true));
		$Config = AssetConfig::buildFromIniFile($testFile);
		$this->Helper->config($Config);
		$this->Helper->Html = new HtmlHelper($view);

		Router::reload();
		Configure::write('debug', 2);
	}
 public function __construct()
 {
     parent::__construct();
     if (!Cache::config(self::CACHE_CONFIG)) {
         Cache::config(self::CACHE_CONFIG, array('engine' => 'File', 'duration' => 300, 'prefix' => 'attachable_', 'probability' => 100, 'serialize' => true, 'path' => MEDIA_CACHE_DIR));
     }
 }
Esempio n. 6
0
 function testConfigChange()
 {
     $result = Cache::config('sessions', array('engine' => 'File', 'path' => TMP . 'sessions'));
     $this->assertEqual($result['settings'], Cache::settings('File'));
     $result = Cache::config('tests', array('engine' => 'File', 'path' => TMP . 'tests'));
     $this->assertEqual($result['settings'], Cache::settings('File'));
 }
Esempio n. 7
0
 /**
  * testDelete function
  *
  * @return void
  * @access public
  */
 function testDelete()
 {
     // Without params
     $this->Shell->delete();
     $this->Shell->expectAt(0, 'out', array(new PatternExpectation('/Usage/')));
     // Invalid config
     $this->Shell->args = array('cache_test');
     $this->Shell->delete();
     $this->Shell->expectAt(0, 'err', array(new PatternExpectation('/not found/')));
     $this->Shell->expectCallCount('_stop', 2);
     Cache::config('cache_test', Cache::config('default'));
     // With config
     Cache::write('anything', array('a'), 'cache_test');
     Cache::write('anything2', array('b'), 'cache_test');
     $this->assertTrue(Cache::read('anything', 'cache_test') !== false);
     $this->Shell->args = array('cache_test');
     $this->Shell->delete();
     $this->assertFalse(Cache::read('anything', 'cache_test'));
     // With config
     Cache::write('anything', array('a'), 'cache_test');
     Cache::write('anything2', array('b'), 'cache_test');
     $this->assertTrue(Cache::read('anything', 'cache_test') !== false);
     $this->Shell->args = array('cache_test', 'anything');
     $this->Shell->delete();
     $this->assertFalse(Cache::read('anything', 'cache_test'));
     $this->assertTrue(Cache::read('anything2', 'cache_test') !== false);
 }
 /**
  * startTest
  *
  * @return void
  */
 public function startTest()
 {
     $this->cache_path = CACHE . 'models' . DS;
     Cache::config('default', array('prefix' => 'cake_', 'engine' => 'File', 'path' => $this->cache_path, 'duration' => '+1 hour'));
     $this->Article = ClassRegistry::init('Article');
     $this->User = ClassRegistry::init('User');
 }
Esempio n. 9
0
 /**
  * Wrapper find to cache sql queries
  * @param array $conditions
  * @param array $fields
  * @param string $order
  * @param string $recursive
  * @return array
  */
 function find($conditions = null, $fields = array(), $order = null, $recursive = null)
 {
     if (Configure::read('Cache.disable') === false && Configure::read('Cache.check') === true && (isset($fields['cache']) && $fields['cache'] !== false || $this->tempCache != null)) {
         if ($this->tempCache != null && isset($fields['cache']) && $fields['cache'] !== false) {
             $fields['cache'] = $this->tempCache;
         }
         $this->tempCache = null;
         $key = $fields['cache'];
         $expires = '+1 hour';
         if (is_array($fields['cache'])) {
             $key = $fields['cache'][0];
             if (isset($fields['cache'][1])) {
                 $expires = $fields['cache'][1];
             }
         }
         // Set cache settings
         Cache::config('sql_cache', array('prefix' => strtolower($this->name) . '-', 'duration' => $expires));
         // Load from cache
         $results = Cache::read($key, 'sql_cache');
         if (!is_array($results)) {
             $results = parent::find($conditions, $fields, $order, $recursive);
             Cache::write($key, $results, 'sql_cache');
         }
         return $results;
     }
     // Not cacheing
     return parent::find($conditions, $fields, $order, $recursive);
 }
 /**
  * startTest
  *
  * @return void
  */
 public function startTest($method)
 {
     $this->cache_path = CACHE;
     Cache::config('default', array('engine' => 'File', 'path' => $this->cache_path, 'duration' => '+10 seconds'));
     $this->Article = ClassRegistry::init('Article');
     $this->User = ClassRegistry::init('User');
 }
Esempio n. 11
0
 function __construct()
 {
     App::import('Xml');
     App::import('Core', 'HttpSocket');
     $this->HttpSocket = new HttpSocket();
     Cache::config('rss', array('engine' => 'File', 'duration' => '+12 hours', 'path' => CACHE . 'rss', 'prefix' => 'rss_'));
     parent::__construct();
 }
 public function __construct()
 {
     parent::__construct();
     $this->Estatistica = new Estatistica();
     $this->EstatisticaTransicao = new EstatisticaTransicao();
     ini_set('memory_limit', '1G');
     Cache::config('_cake_model_', array('engine' => 'File', 'prefix' => 'shell' . 'cake_model_', 'path' => CACHE . 'models' . DS, 'serialize' => true, 'duration' => '+999 days'));
 }
Esempio n. 13
0
 public function tearDown()
 {
     Cache::delete('test' . 'Setting.cache');
     Cache::clear();
     @unlink(TMP . 'tests' . DS . 'cake_test_setting_cache');
     Configure::write('Cache.disable', $this->_cacheDisable);
     Cache::config('default', $this->_defaultCacheConfig['settings']);
 }
Esempio n. 14
0
 /**
  * Get the models from Cake by their name
  */
 public function __construct()
 {
     $this->tagModel = ClassRegistry::init($this->tagName);
     $this->listModel = ClassRegistry::init($this->listName);
     if (Cache::config('tagcloud') === false) {
         Cache::config('tagcloud', array('engine' => 'File', 'serialize' => true, 'prefix' => ''));
     }
 }
Esempio n. 15
0
 /**
  * TinyAuthorize::__construct()
  *
  * @param ComponentCollection $Collection
  * @param array $config
  */
 public function __construct(ComponentCollection $Collection, $config = [])
 {
     $config += $this->_defaultConfig;
     parent::__construct($Collection, $config);
     if (Cache::config($config['cache']) === false) {
         throw new CakeException(sprintf('TinyAuth could not find `%s` cache - expects at least a `default` cache', $config['cache']));
     }
 }
Esempio n. 16
0
 function init($settings = array())
 {
     parent::init(array_merge(array('engine' => 'SuperStack', 'prefix' => Inflector::slug(APP_DIR) . '_'), $settings));
     foreach ($settings['stack'] as $key => $stack) {
         Cache::config($key, $stack);
     }
     return true;
 }
 /**
  * Writing cache entries with duration = 0 (forever) should work.
  *
  * @return void
  */
 public function testReadWriteDurationZero()
 {
     Cache::config('apc', array('engine' => 'Apc', 'duration' => 0, 'prefix' => 'cake_'));
     Cache::write('zero', 'Should save', 'apc');
     sleep(1);
     $result = Cache::read('zero', 'apc');
     $this->assertEquals('Should save', $result);
 }
Esempio n. 18
0
/**
 * test case startup
 *
 * @return void
 */
	public static function setupBeforeClass() {
		Cache::config('session_test', array(
			'engine' => 'File',
			'prefix' => 'session_test_'
		));
		self::$_sessionBackup = Configure::read('Session');

		Configure::write('Session.handler.config', 'session_test');
	}
Esempio n. 19
0
 public function __construct(ComponentCollection $Collection, $settings = array())
 {
     $settings = am($this->_defaults, $settings);
     parent::__construct($Collection, $settings);
     if (Cache::config($settings['cache']) === false) {
         throw new CakeException(__('TinyAuth could not find `%s` cache - expects at least a `default` cache', $settings['cache']));
     }
     $this->_matchArray = $this->_getRoles();
 }
Esempio n. 20
0
 public function setUp()
 {
     $this->disabled = Configure::read('Cache.disable');
     Configure::write('Cache.disable', false);
     $this->slugCache = SlugCache::config();
     Cache::config('SluggerTest', array('engine' => 'File', 'duration' => '+1 days', 'prefix' => 'slugger_test_'));
     SlugCache::config('SluggerTest');
     parent::setUp();
 }
Esempio n. 21
0
 function setUp()
 {
     Cache::drop(AssetConfig::CACHE_CONFIG);
     Cache::config(AssetConfig::CACHE_CONFIG, array('engine' => 'File'));
     $this->_pluginPath = App::pluginPath('AssetCompress');
     $this->testConfig = $this->_pluginPath . 'tests' . DS . 'test_files' . DS . 'config' . DS . 'config.ini';
     AssetConfig::clearAllCachedKeys();
     $this->config = AssetConfig::buildFromIniFile($this->testConfig);
 }
Esempio n. 22
0
 function beforeFilter()
 {
     Cache::config(array('duration' => '1 hour'));
     if (false === ($setting = Cache::read('Gallery.jslibs'))) {
         $setting = ClassRegistry::init('Setting')->findByKey('Gallery.jslibs');
         Cache::write('Gallery.jslibs', $setting);
     }
     Configure::write('Gallery.jslibs', $setting['Setting']['value']);
     return parent::beforeFilter();
 }
Esempio n. 23
0
 public function __construct($View, $options = array())
 {
     $this->settings['markdownFilePath'] = APP . 'View' . DS . 'Elements' . DS . 'markdown' . DS;
     $this->settings['cachePath'] = TMP . 'cache' . DS . 'yamd' . DS;
     $this->settings = array_merge($this->settings, $options);
     $obj = new Folder($this->settings['cachePath'], true, 0777);
     Cache::config($this->settings['cacheConfig'], array('engine' => 'File', 'path' => $this->settings['cachePath']));
     $this->l10n = new L10n();
     parent::__construct($View, $options);
 }
Esempio n. 24
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. 25
0
 /**
  * one initial call of config() is required. (empty parameters for default settings is fine)
  * you will either get a failed enforce or "Trying to get property of non-object"
  */
 public static function config(array $config = array())
 {
     // merge given (precedence) and default config
     self::$config = (object) array_merge(self::$defaultConfig, $config);
     $c =& self::$config;
     // shorthand
     $c->ROOT = rtrim($_SERVER['DOCUMENT_ROOT'], '/');
     // normalize trailing
     $c->CACHEPATH = $c->ROOT . '/' . $c->CACHEPATH;
     enforce(is_dir($c->CACHEPATH), "invalid cache directory {$c->CACHEPATH}");
 }
Esempio n. 26
0
 /**
  * Apply the cache settings.
  *
  * @param array $config
  */
 public function __construct($config = array())
 {
     parent::__construct($config);
     if (Cache::config('feeds') === false) {
         $cachePath = CACHE . 'feeds' . DS;
         if (!file_exists($cachePath)) {
             $folder = new Folder();
             $folder->create($cachePath, 0777);
         }
         Cache::config('feeds', array('engine' => 'File', 'serialize' => true, 'prefix' => 'feed_', 'path' => $cachePath, 'duration' => '+1 day'));
     }
 }
 public function setUp()
 {
     parent::setUp();
     Cache::drop(AssetConfig::CACHE_CONFIG);
     Cache::config(AssetConfig::CACHE_CONFIG, array('engine' => 'File'));
     $this->_pluginPath = App::pluginPath('AssetCompress');
     $this->_testFiles = App::pluginPath('AssetCompress') . 'Test' . DS . 'test_files' . DS;
     $this->testConfig = $this->_testFiles . 'Config' . DS . 'config.ini';
     $this->_themeConfig = $this->_testFiles . 'Config' . DS . 'themed.ini';
     AssetConfig::clearAllCachedKeys();
     $this->config = AssetConfig::buildFromIniFile($this->testConfig);
 }
Esempio n. 28
0
 function __construct($config)
 {
     parent::__construct($config);
     App::import('HttpSocket');
     $this->Http = new HttpSocket();
     App::import('Xml');
     $this->Xml = new Xml();
     Cache::config('google_analytics', array('engine' => 'File', 'duration' => '+5 minutes'));
     if ($token = Cache::read('GoogleAnalytics.token')) {
         $this->token = $token;
     }
 }
Esempio n. 29
0
 /**
  * Configure cache config
  *
  * @throws CacheException
  */
 public static function config($name = null, $settings = array())
 {
     if (version_compare(Configure::version(), '2.4', '>=')) {
         return parent::config($name, $settings);
     }
     $return = parent::config($name, $settings);
     foreach (self::$_config[$name]['groups'] as $group) {
         self::$_groups[$group][] = $name;
         sort(self::$_groups[$group]);
         self::$_groups[$group] = array_unique(self::$_groups[$group]);
     }
     return $return;
 }
Esempio n. 30
0
 /**
  * Initializes configure and runs the bootstrap process.
  * Bootstrapping includes the following steps:
  *
  * - Setup App array in Configure.
  * - Include app/config/core.php.
  * - Configure core cache configurations.
  * - Load App cache files.
  * - Include app/config/bootstrap.php.
  * - Setup error/exception handlers.
  *
  * @return void
  */
 public static function bootstrap($boot = true)
 {
     if ($boot) {
         self::write('App', array('base' => false, 'baseUrl' => false, 'dir' => APP_DIR, 'webroot' => WEBROOT_DIR, 'www_root' => WWW_ROOT));
         if (!(include CONFIGS . 'core.php')) {
             trigger_error(__("Can't find application core file. Please create %score.php, and make sure it is readable by PHP.", CONFIGS), E_USER_ERROR);
         }
         if (empty(self::$_values['Cache']['disable'])) {
             $cache = Cache::config('default');
             if (empty($cache['settings'])) {
                 trigger_error(__('Cache not configured properly. Please check Cache::config(); in APP/config/core.php'), E_USER_WARNING);
                 $cache = Cache::config('default', array('engine' => 'File'));
             }
             $path = $prefix = $duration = null;
             if (!empty($cache['settings']['path'])) {
                 $path = realpath($cache['settings']['path']);
             } else {
                 $prefix = $cache['settings']['prefix'];
             }
             if (self::$_values['debug'] >= 1) {
                 $duration = '+10 seconds';
             } else {
                 $duration = '+999 days';
             }
             if (Cache::config('_cake_core_') === false) {
                 Cache::config('_cake_core_', array_merge((array) $cache['settings'], array('prefix' => $prefix . 'cake_core_', 'path' => $path . DS . 'persistent' . DS, 'serialize' => true, 'duration' => $duration)));
             }
             if (Cache::config('_cake_model_') === false) {
                 Cache::config('_cake_model_', array_merge((array) $cache['settings'], array('prefix' => $prefix . 'cake_model_', 'path' => $path . DS . 'models' . DS, 'serialize' => true, 'duration' => $duration)));
             }
         }
         App::init();
         App::build();
         if (!(include CONFIGS . 'bootstrap.php')) {
             trigger_error(__("Can't find application bootstrap file. Please create %sbootstrap.php, and make sure it is readable by PHP.", CONFIGS), E_USER_ERROR);
         }
         $level = -1;
         if (isset(self::$_values['Error']['level'])) {
             error_reporting(self::$_values['Error']['level']);
             $level = self::$_values['Error']['level'];
         }
         if (!empty(self::$_values['Error']['handler'])) {
             set_error_handler(self::$_values['Error']['handler'], $level);
         }
         if (!empty(self::$_values['Exception']['handler'])) {
             set_exception_handler(self::$_values['Exception']['handler']);
         }
     }
 }