コード例 #1
0
ファイル: App.php プロジェクト: eneiasramos/Made_Cache
 /**
  * Version of _initModules that locks the requests using redis and
  * effectively blocks every parallell request that would otherwise
  * regenerate the cache.
  *
  * @see Made_Cache_Model_Config
  * @return $this
  */
 protected function _initModulesSafe()
 {
     if ($this->_config->loadModulesCache()) {
         return $this;
     }
     $backend = Mage::app()->getCacheInstance()->getFrontend()->getBackend();
     $options = $this->_config->getLockingOptions();
     // Spin lock
     $lockSpun = false;
     while (!$backend->acquireLock($options['lock_name'], $options['token'], $options['lock_timeout'], $lockSpun)) {
         $lockSpun = true;
         usleep($options['spin_timeout']);
     }
     if ($lockSpun) {
         // The cache might have been generated while we waited for the lock
         if ($this->_config->loadModulesCache()) {
             $backend->releaseLock($options['lock_name'], $options['token']);
             return $this;
         }
     }
     $this->_config->loadModules();
     if ($this->_config->isLocalConfigLoaded() && !$this->_shouldSkipProcessModulesUpdates()) {
         Varien_Profiler::start('mage::app::init::apply_db_schema_updates');
         Mage_Core_Model_Resource_Setup::applyAllUpdates();
         Varien_Profiler::stop('mage::app::init::apply_db_schema_updates');
     }
     $this->_config->loadDb();
     $this->_config->saveCache();
     $backend->releaseLock($options['lock_name'], $options['token']);
     return $this;
 }