5

I'm trying to find out the way to get store configuration values (Mage::getStoreConfig($path, $store)) from cache. The reason for this is that I don't want to make db connections every time I'm calling the configuration values. Is there a way to use cache for the said purpose?

thanks

4

Calling Mage::getStoreConfig automatically uses Magento cache.

It uses the getConfig method from Mage_Core_Model_Store which as you can see return the value from the cache if set:

public function getConfig($path)
{
    if (isset($this->_configCache[$path])) {
        return $this->_configCache[$path];
    }

    $config = Mage::getConfig();

    $fullPath = 'stores/' . $this->getCode() . '/' . $path;
    $data = $config->getNode($fullPath);
    if (!$data && !Mage::isInstalled()) {
        $data = $config->getNode('default/' . $path);
    }
    if (!$data) {
        return null;
    }
    return $this->_processConfigValue($fullPath, $path, $data);
}

The $_configCache is initiated via the initConfigCache method from Mage_Core_Model_App which is itself called during the _initStores method. If we continue, the _initStores method is called during the _initCurrentStore, itself called when Mage::run is called.

3

Mage::getStoreConfig($path,$store) is already stored in cache if you look in this file app\code\core\Mage\Core\Model\App.php

protected function _initModules()
{
    if (!$this->_config->loadModulesCache()) {
        $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();
    }
    return $this;
}

To verify if values coming from cache, change value direct from db table core_config_data you will see the result

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.