magento-lts icon indicating copy to clipboard operation
magento-lts copied to clipboard

Add new method to get config value directly from DB bypassing cache.

Open kiatng opened this issue 6 months ago • 1 comments

Description (*)

We can save a config value by

Mage::getConfig()->saveConfig($path, $newValue);

However, if cache is enabled, after saving $newValue, the following will return the old value:

Mage::getStoreConfig($path);

To get the new value, we need to refresh the cache with Mage::getConfig()->reinit();.

In my use case, I needed to get and update config value in a cron running constantly. It's not good idea to keep refreshing cache. (Also, I need to allow admin users to edit the value in the System Configuration. It turns out that values here are updated and not from the cache.)

With this PR, we can get the current value by

Mage::getResourceSingleton('core/config')->getValue($path);

Fixed Issues (if relevant)

Over the years, others need similar feature, see stackoverflow

Manual testing scenarios (*)

$path = 'test/config';
Mage::getConfig()->saveConfig($path, 'foo');
echo Mage::getStoreConfig($path); // null
echo Mage::getResourceSingleton('core/config')->getValue($path); // foo

kiatng avatar Aug 24 '24 02:08 kiatng