3

I'm trying to get config values using:

$this->_scopeConfig->getValue(
    $config_path,
    \Magento\Store\Model\ScopeInterface::SCOPE_STORE
);

& it returns the cached value.
Is there any way to make it skip the cache without disabling it?
*I want the cache to be enabled but still bypass it for this value only.
**I also don't want to always clear the cache programmatically before getting it.
-- Any idea?


1

1 Answer 1

3

you can use below code to get system config value even if caching is enable.

<?php
namespace Vendor\Extension\Helper;

use Magento\Framework\App\Helper\Context;

class Data extends AbstractHelper
{
    private $configCollection;

    public function __construct(Context $context,
                                \Magento\Config\Model\ResourceModel\Config\Data\CollectionFactory $configCollection)
    {
        $this->configCollection = $configCollection;
        parent::__construct($context);
    }
  
    public function getFieldValue()
    {
        $collection = $this->configCollection->create();
        $collection->addFieldToFilter("path",['eq'=>"path/section/field"]);
        if($collection->count()>0){
            return $collection->getFirstItem()->getData()['value'];
        }
        else
        {
            return "";
        }

    }

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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