1

when i do

 return $this->_scopeConfig->getValue("config/user/email", \Magento\Store\Model\ScopeInterface::SCOPE_STORE);

Gets the value of the cache and is not correct. How can I make it skip the cache?

3
  • Why do you not want to use the default caching mechanism? Does it work after you refresh the cache?
    – thaddeusmt
    Commented Jun 23, 2017 at 19:24
  • Because i change the value but i obtain the old
    – Miguel
    Commented Jun 23, 2017 at 20:51
  • You shouldn't have to clear the cache every time - that will be very slow. If you are changing the configuration value so often that you have to clear the cache every time, you should probably be using another form of storage. After updating the configuration (which should be infrequently), running $ bin/magento cache:clean should update the configuration cache. Or you can do it in the Admin Cache Management area as well.
    – thaddeusmt
    Commented Jun 26, 2017 at 14:28

1 Answer 1

7

Inject the following dependency into your constructor

/**
 * @var \Magento\Framework\App\Cache\TypeListInterface
 */
protected $cacheTypeList;

/**
 * @param \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList
 */
public function __construct(
    \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList
) {
    $this->cacheTypeList = $cacheTypeList;
}

and then try to add before you return your new config value the following lines

$this->cacheTypeList->cleanType(\Magento\Framework\App\Cache\Type\Config::TYPE_IDENTIFIER); $this->cacheTypeList->cleanType(\Magento\PageCache\Model\Cache\Type::TYPE_IDENTIFIER);

3
  • It is very slow performing these actions, right? Or is it because I'm in localhost?
    – Miguel
    Commented Jun 26, 2017 at 14:08
  • The cache is there to speed up getting config values - if you rebuild the entire config cache each time (instead of using the cache), it will be very slow.
    – thaddeusmt
    Commented Jun 26, 2017 at 14:25
  • No, is only for render a form login that depends the config value, i think that the clean of cache will be one time or less for month
    – Miguel
    Commented Jun 26, 2017 at 14:47

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.