Exemplo n.º 1
0
 private function writeDBLog($method, $requestData, $responseType, $_response = '', $proxy_used = '', $curlStatus = '')
 {
     $this->loadModel('LogAutoxp')->clear();
     $ip = $_SERVER['REMOTE_ADDR'];
     $proxy_type = $this->isBot($ip) ? 'Bot' : 'Site';
     $this->loadModel('LogAutoxp')->save(array('ip_type' => $proxy_type, 'ip' => $ip, 'host' => gethostbyaddr($ip), 'ip_details' => json_encode($_SERVER), 'proxy_used' => $proxy_used, 'method' => $method, 'request' => $this->getRequestURL($requestData, $method), 'response_type' => $responseType, 'response_status' => $curlStatus ? json_encode($curlStatus) : '', 'response' => $_response, 'cache_id' => $responseType == 'CACHE' ? Hash::get(Cache::settings('autoxp'), 'data.id') : 0, 'cache' => $responseType == 'CACHE' ? Hash::get(Cache::settings('autoxp'), 'data.value') : ''));
 }
Exemplo n.º 2
0
 function testInitSettings()
 {
     Cache::engine('File', array('path' => TMP . 'tests'));
     $settings = Cache::settings();
     $expecting = array('duration' => 3600, 'probability' => 100, 'path' => TMP . 'tests', 'prefix' => 'cake_', 'lock' => false, 'serialize' => true);
     $this->assertEqual($settings, $expecting);
 }
Exemplo n.º 3
0
 /**
  * testSettings method
  *
  * @return void
  */
 public function testSettings()
 {
     $settings = Cache::settings('memcached');
     unset($settings['path']);
     $expecting = array('prefix' => 'cake_', 'duration' => 3600, 'probability' => 100, 'servers' => array('127.0.0.1'), 'persistent' => false, 'compress' => false, 'engine' => 'Memcached', 'login' => null, 'password' => null, 'groups' => array(), 'serialize' => 'php', 'options' => array());
     $this->assertEquals($expecting, $settings);
 }
Exemplo n.º 4
0
 /**
  * testCacheDirChange method
  *
  * @return void
  */
 public function testCacheDirChange()
 {
     $result = Cache::config('sessions', array('engine' => 'File', 'path' => TMP . 'sessions'));
     $this->assertEquals($result['settings'], Cache::settings('sessions'));
     $result = Cache::config('sessions', array('engine' => 'File', 'path' => TMP . 'tests'));
     $this->assertEquals($result['settings'], Cache::settings('sessions'));
     $this->assertNotEquals($result['settings'], Cache::settings('default'));
 }
 /**
  * testSettings method
  *
  * @return void
  */
 public function testSettings()
 {
     $settings = Cache::settings();
     $expecting = array('prefix' => 'cake_', 'duration' => 3600, 'probability' => 100, 'engine' => 'Xcache');
     $this->assertTrue(isset($settings['PHP_AUTH_USER']));
     $this->assertTrue(isset($settings['PHP_AUTH_PW']));
     unset($settings['PHP_AUTH_USER'], $settings['PHP_AUTH_PW']);
     $this->assertEquals($settings, $expecting);
 }
Exemplo n.º 6
0
 /**
  * _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);
     }
 }
Exemplo n.º 7
0
 /**
  * Output parsed JLM javascript file
  *
  * The output is cached when not in debug mode.
  */
 function wf_jlm()
 {
     $javascripts = Cache::read('wf_jlm');
     if (empty($javascripts) or Configure::read('debug') > 0) {
         $javascripts = $this->JlmPackager->concate();
         Cache::write('wf_jlm', $javascripts);
     }
     $this->layout = false;
     $this->set(compact('javascripts'));
     $this->RequestHandler->respondAs('application/javascript');
     $cacheSettings = Cache::settings();
     $file = CACHE . $cacheSettings['prefix'] . 'wf_jlm';
     $this->JlmPackager->browserCacheHeaders(filemtime($file));
     Configure::write('debug', 0);
 }
Exemplo n.º 8
0
 /**
  * testConnect method
  *
  * @return void
  */
 public function testConnect()
 {
     $Memcache = new MemcacheEngine();
     $Memcache->init(Cache::settings('memcache'));
     $result = $Memcache->connect('127.0.0.1');
     $this->assertTrue($result);
 }
Exemplo n.º 9
0
 /**
  * testSettings method
  *
  * @access public
  * @return void
  */
 function testSettings()
 {
     $settings = Cache::settings();
     $expecting = array('prefix' => 'cake_', 'duration' => 3600, 'probability' => 100, 'servers' => array('127.0.0.1'), 'compress' => false, 'engine' => 'Memcache');
     $this->assertEqual($settings, $expecting);
 }
Exemplo n.º 10
0
 /**
  * testSettings method
  *
  * @access public
  * @return void
  */
 function testSettings()
 {
     $settings = Cache::settings();
     $expecting = array('prefix' => 'cake_', 'duration' => 3600, 'probability' => 100, 'engine' => 'Xcache', 'PHP_AUTH_USER' => 'user', 'PHP_AUTH_PW' => 'password');
     $this->assertEqual($settings, $expecting);
 }
Exemplo n.º 11
0
 /**
  * testSet method
  *
  * @access public
  * @return void
  */
 function testSet()
 {
     $_cacheSet = Cache::set();
     Cache::set(array('duration' => '+1 year'));
     $data = Cache::read('test_cache');
     $this->assertFalse($data);
     $data = 'this is just a simple test of the cache system';
     $write = Cache::write('test_cache', $data);
     $this->assertTrue($write);
     Cache::set(array('duration' => '+1 year'));
     $data = Cache::read('test_cache');
     $this->assertEqual($data, 'this is just a simple test of the cache system');
     Cache::delete('test_cache');
     $global = Cache::settings();
     Cache::set($_cacheSet);
 }
 /**
  * Updates the Bayesian average(s) for affected items.
  *
  * @param object $Model Ratings model this applies to
  * @param number $itemId ID of item whose ratings are being saved. Updates everything if this is false.
  * @access public
  */
 function updateBayesianAverage(&$Model, $itemId = false)
 {
     extract($this->__settings[$Model->alias]);
     $ItemModel =& $this->getItemModel($Model);
     $updateConditions = array($ItemModel->alias . '.' . $fields['ratingsCount'] . ' >' => '0');
     $updateSingle = $itemId ? true : false;
     # whether to update Bayesian avg just for this itemId or all items
     // Get constant/mean average from cache or db if either is inexplicit
     if (!$C || !$m) {
         $cache['data'] = Cache::read($cache['prefix'] . $Model->alias, $cache['config']);
         if (!$cache['calculationDuration']) {
             $cacheSettings = Cache::settings();
             $cache['calculationDuration'] = $cacheSettings['duration'] / 2;
         }
         if (!$cache['data'] || time() - $cache['data']['time'] > $cache['calculationDuration']) {
             // Calculate latest Constant and mean from the database
             $allStats = $ItemModel->find('first', array('fields' => array("AVG({$ItemModel->alias}.{$fields['ratingsCount']}) C", "AVG({$ItemModel->alias}.{$fields['meanRating']}) m"), 'conditions' => array("{$ItemModel->alias}.{$fields['ratingsCount']} >" => '0'), 'recursive' => -1));
             if (!$C) {
                 // If cache value isn't set or the difference between it and the current value is greater than 10%, update the cache and all items
                 if (!isset($cache['data']['C']) || abs($allStats[0]['C'] - $cache['data']['C']) > $cache['data']['C'] * 0.1) {
                     $C = $allStats[0]['C'];
                     $updateSingle = false;
                 } else {
                     $C = $cache['data']['C'];
                 }
             }
             if (!$m) {
                 // If cache value isn't set or the difference between it and the current value is greater than 10%, update the cache and all items
                 if (!isset($cache['data']['m']) || abs($allStats[0]['m'] - $cache['data']['m']) > $cache['data']['m'] * 0.1) {
                     $m = $allStats[0]['m'];
                     $updateSingle = false;
                 } else {
                     $m = $cache['data']['m'];
                 }
             }
             // Update the cache
             Cache::write($cache['prefix'] . $Model->alias, array('time' => time(), 'C' => $C, 'm' => $m), $cache['config']);
         } else {
             $C = $cache['data']['C'];
             $m = $cache['data']['m'];
         }
     }
     // Only update the data for one item
     if ($updateSingle) {
         if ($useForeignKey) {
             $updateConditions["{$ItemModel->alias}.{$fields['itemId']}"] = $itemId;
         } else {
             $updateConditions["{$ItemModel->alias}.{$ItemModel->primaryKey}"] = $itemId;
         }
     }
     // Update the affected items' bayesian averages
     if ($C > 2) {
         $n = $ItemModel->escapeField($fields['ratingsCount']);
         $j = $ItemModel->escapeField($fields['meanRating']);
         $formula = "({$n} / ({$n} + {$C})) * {$j} + ({$C} / ({$n} + {$C})) * {$m}";
     } else {
         $formula = $ItemModel->escapeField($fields['meanRating']);
     }
     $ItemModel->updateAll(array($ItemModel->alias . '.' . $fields['bayesianRating'] => $formula), $updateConditions);
 }
Exemplo n.º 13
0
 /**
  * Test deleting specific cache data
  *
  * @since   0.1
  * @author  Joshua McNeese <*****@*****.**>
  * @return  void
  */
 public function testClearCached()
 {
     $uuid1 = String::uuid();
     $key1 = 'test';
     $data1 = array('foo', 'bar', 'baz');
     $this->CacheThing->setCached($key1, $data1);
     $this->CacheThing->setCached($key1, $data1, $uuid1);
     $result1 = $this->CacheThing->clearCached(false);
     $this->assertTrue($result1);
     $config1 = Cache::settings($this->CacheThing->getCacheConfig());
     $folder1 = new Folder($config1['path']);
     $contents1 = $folder1->read();
     $this->assertTrue(count($contents1['1']) == 0);
     $result2 = $this->CacheThing->clearCached(false, $uuid1);
     $this->assertTrue($result2);
     $config2 = Cache::settings($this->CacheThing->getCacheConfig($uuid1));
     $folder2 = new Folder($config2['path']);
     $contents2 = $folder2->read();
     $this->assertTrue(count($contents2['1']) == 0);
 }
Exemplo n.º 14
0
 function getPrefixCacheKey($key, $config = 'default')
 {
     $settings = Cache::settings($config);
     if (empty($settings) || !self::isInitialized($config)) {
         return '';
     }
     $key = MemcacheEngine::key($key);
     if (!$key) {
         return '';
     }
     return $settings['prefix'] . $key;
 }
Exemplo n.º 15
0
 /**
  * Loads the app/config/bootstrap.php
  * If the alternative paths are set in this file
  * they will be added to the paths vars
  *
  * @param boolean $boot Load application bootstrap (if true)
  * @access private
  */
 function __loadBootstrap($boot)
 {
     $_this =& Configure::getInstance(false);
     $modelPaths = $behaviorPaths = $controllerPaths = $componentPaths = $viewPaths = $helperPaths = $pluginPaths = $vendorPaths = null;
     if ($boot) {
         $_this->write('App', array('base' => false, 'baseUrl' => false, 'dir' => APP_DIR, 'webroot' => WEBROOT_DIR));
         if (php_sapi_name() == 'isapi') {
             $_this->write('App.server', 'IIS');
         }
         if (!(include APP_PATH . 'config' . DS . 'core.php')) {
             trigger_error(sprintf(__("Can't find application core file. Please create %score.php, and make sure it is readable by PHP.", true), CONFIGS), E_USER_ERROR);
         }
         if (!(include APP_PATH . 'config' . DS . 'bootstrap.php')) {
             trigger_error(sprintf(__("Can't find application bootstrap file. Please create %sbootstrap.php, and make sure it is readable by PHP.", true), CONFIGS), E_USER_ERROR);
         }
         if ($_this->read('Cache.disable') !== true) {
             $cache = Cache::settings();
             if (empty($cache)) {
                 trigger_error('Cache not configured properly. Please check Cache::config(); in APP/config/core.php', E_USER_WARNING);
                 list($engine, $cache) = Cache::config('default', array('engine' => 'File'));
             }
             if (Configure::read() > 1) {
                 $cache['duration'] = 10;
             }
             $settings = array('prefix' => 'cake_core_', 'path' => CACHE . 'persistent' . DS, 'serialize' => true);
             $config = Cache::config('_cake_core_', array_merge($cache, $settings));
         }
     }
     $_this->__buildPaths(compact('modelPaths', 'viewPaths', 'controllerPaths', 'helperPaths', 'componentPaths', 'behaviorPaths', 'pluginPaths'));
     if (defined('BASE_URL')) {
         trigger_error('BASE_URL Deprecated: See Configure::write(\'App.baseUrl\', \'' . BASE_URL . '\');  in APP/config/core.php', E_USER_WARNING);
         $_this->write('App.baseUrl', BASE_URL);
     }
     if (defined('DEBUG')) {
         trigger_error('DEBUG Deprecated: Use Configure::write(\'debug\', ' . DEBUG . ');  in APP/config/core.php', E_USER_WARNING);
         $_this->write('debug', DEBUG);
     }
     if (defined('CAKE_ADMIN')) {
         trigger_error('CAKE_ADMIN Deprecated: Use Configure::write(\'Routing.admin\', \'' . CAKE_ADMIN . '\');  in APP/config/core.php', E_USER_WARNING);
         $_this->write('Routing.admin', CAKE_ADMIN);
     }
     if (defined('WEBSERVICES')) {
         trigger_error('WEBSERVICES Deprecated: Use Router::parseExtensions(); or add Configure::write(\'Routing.webservices\', \'' . WEBSERVICES . '\');', E_USER_WARNING);
         $_this->write('Routing.webservices', WEBSERVICES);
     }
     if (defined('ACL_CLASSNAME')) {
         trigger_error('ACL_CLASSNAME Deprecated. Use Configure::write(\'Acl.classname\', \'' . ACL_CLASSNAME . '\'); in APP/config/core.php', E_USER_WARNING);
         $_this->write('Acl.classname', ACL_CLASSNAME);
     }
     if (defined('ACL_DATABASE')) {
         trigger_error('ACL_DATABASE Deprecated. Use Configure::write(\'Acl.database\', \'' . ACL_CLASSNAME . '\'); in APP/config/core.php', E_USER_WARNING);
         $_this->write('Acl.database', ACL_CLASSNAME);
     }
     if (defined('CAKE_SESSION_SAVE')) {
         trigger_error('CAKE_SESSION_SAVE Deprecated. Use Configure::write(\'Session.save\', \'' . CAKE_SESSION_SAVE . '\'); in APP/config/core.php', E_USER_WARNING);
         $_this->write('Session.save', CAKE_SESSION_SAVE);
     }
     if (defined('CAKE_SESSION_TABLE')) {
         trigger_error('CAKE_SESSION_TABLE Deprecated. Use Configure::write(\'Session.table\', \'' . CAKE_SESSION_TABLE . '\'); in APP/config/core.php', E_USER_WARNING);
         $_this->write('Session.table', CAKE_SESSION_TABLE);
     }
     if (defined('CAKE_SESSION_STRING')) {
         trigger_error('CAKE_SESSION_STRING Deprecated. Use Configure::write(\'Security.salt\', \'' . CAKE_SESSION_STRING . '\'); in APP/config/core.php', E_USER_WARNING);
         $_this->write('Security.salt', CAKE_SESSION_STRING);
     }
     if (defined('CAKE_SESSION_COOKIE')) {
         trigger_error('CAKE_SESSION_COOKIE Deprecated. Use Configure::write(\'Session.cookie\', \'' . CAKE_SESSION_COOKIE . '\'); in APP/config/core.php', E_USER_WARNING);
         $_this->write('Session.cookie', CAKE_SESSION_COOKIE);
     }
     if (defined('CAKE_SECURITY')) {
         trigger_error('CAKE_SECURITY Deprecated. Use Configure::write(\'Security.level\', \'' . CAKE_SECURITY . '\'); in APP/config/core.php', E_USER_WARNING);
         $_this->write('Security.level', CAKE_SECURITY);
     }
     if (defined('CAKE_SESSION_TIMEOUT')) {
         trigger_error('CAKE_SESSION_TIMEOUT Deprecated. Use Configure::write(\'Session.timeout\', \'' . CAKE_SESSION_TIMEOUT . '\'); in APP/config/core.php', E_USER_WARNING);
         $_this->write('Session.timeout', CAKE_SESSION_TIMEOUT);
     }
     if (defined('AUTO_SESSION')) {
         trigger_error('AUTO_SESSION Deprecated. Use Configure::write(\'Session.start\', \'' . AUTO_SESSION . '\'); in APP/config/core.php', E_USER_WARNING);
         $_this->write('Session.start', (bool) AUTO_SESSION);
     }
 }
Exemplo n.º 16
0
 function testSettings()
 {
     $settings = Cache::settings();
     $expecting = array('duration' => 3600, 'probability' => 100, 'className' => 'CacheTestModel', 'fields' => array('data', 'expires'), 'serialize' => true, 'engine' => 'Model');
     $this->assertEqual($settings, $expecting);
 }
Exemplo n.º 17
0
}
if (!defined('SERVER_IIS') && php_sapi_name() == 'isapi') {
    define('SERVER_IIS', true);
}
/**
 * Configuration, directory layout and standard libraries
 */
if (!isset($bootstrap)) {
    require CORE_PATH . 'cake' . DS . 'basics.php';
    $TIME_START = getMicrotime();
    require CORE_PATH . 'cake' . DS . 'config' . DS . 'paths.php';
    require LIBS . 'object.php';
    require LIBS . 'inflector.php';
    require LIBS . 'configure.php';
}
require LIBS . 'cache.php';
Configure::getInstance();
if (Configure::read('Cache.disable') !== true) {
    $cache = Cache::settings();
    if (empty($cache)) {
        trigger_error('Cache not configured. Please use Cache::config(); in APP/config/core.php', E_USER_WARNING);
        Cache::config('default', array('engine' => 'File'));
    }
}
require LIBS . 'session.php';
require LIBS . 'security.php';
require LIBS . 'string.php';
Configure::store(null, 'class.paths');
Configure::load('class.paths');
$url = null;
require CAKE . 'dispatcher.php';
 /**
  * test set() parameter handling for user cache configs.
  *
  * @return void
  */
 public function testSetOnAlternateConfigs()
 {
     Cache::config('file_config', array('engine' => 'File', 'prefix' => 'test_file_'));
     Cache::set(array('duration' => '+1 year'), 'file_config');
     $settings = Cache::settings('file_config');
     $this->assertEquals('test_file_', $settings['prefix']);
     $this->assertEquals(strtotime('+1 year') - time(), $settings['duration']);
 }
Exemplo n.º 19
0
 /**
  * testSettings method
  *
  * @access public
  * @return void
  */
 function testMultipleServers()
 {
     $servers = array('127.0.0.1:11211', '127.0.0.1:11222');
     $Cache =& Cache::getInstance();
     $MemCache =& $Cache->_Engine['Memcache'];
     $available = true;
     foreach ($servers as $server) {
         list($host, $port) = explode(':', $server);
         if (!@$MemCache->__Memcache->connect($host, $port)) {
             $available = false;
         }
     }
     if ($this->skipIf(!$available, '%s Need memcache servers at ' . implode(', ', $servers) . ' to run this test')) {
         return;
     }
     unset($MemCache->__Memcache);
     $MemCache->init(array('engine' => 'Memcache', 'servers' => $servers));
     $servers = array_keys($MemCache->__Memcache->getExtendedStats());
     $settings = Cache::settings();
     $this->assertEqual($servers, $settings['servers']);
 }
Exemplo n.º 20
0
 /**
  * testConnect method
  *
  * @return void
  */
 public function testConnect()
 {
     $Redis = new RedisEngine();
     $this->assertTrue($Redis->init(Cache::settings('redis')));
 }
 /**
  * _doCachingRuntimeSetup
  * 
  * @param Model $model
  * @param array $query 
  */
 protected function _doCachingRuntimeSetup(Model $model, &$query)
 {
     // Treat the cache config as a named cache config
     if (is_string($query['autocache'])) {
         $this->runtime['config'] = $query['autocache'];
         $this->runtime['name'] = $this->_generateCacheName($model, $query);
         // All other cache setups
     } else {
         // Manage the cache config
         if (isset($query['autocache']['config']) && !empty($query['autocache']['config'])) {
             $this->runtime['config'] = $query['autocache']['config'];
         } else {
             $this->runtime['config'] = $this->runtime['cache_config_name_default'];
         }
         // Manage the cache name
         if (isset($query['autocache']['name']) && !empty($query['autocache']['name'])) {
             $this->runtime['name'] = $query['autocache']['name'];
         } else {
             $this->runtime['name'] = $this->_generateCacheName($model, $query);
         }
     }
     // Check the cache config really exists, else caching will silently not occur
     if ($this->runtime['cache_config_name_check'] && !Configure::read('Cache.disable') && empty(Cache::settings($this->runtime['config']))) {
         throw new AutocacheException('Attempting to use undefined cache configuration named "' . $this->runtime['config'] . '"');
     }
     // Cache flush control
     if (isset($query['autocache']['flush']) && $query['autocache']['flush'] === true) {
         $this->runtime['flush'] = true;
     }
 }