I have got some data from an API, i like to store those data to cache and update it once a day. I mean i don't like to call the API for each frontend page load. I found this function

if (!function_exists('trustedshopscachecheck')) {
    function trustedshopscachecheck($filename_cache, $timeout = 10800) {
        if (file_exists($filename_cache) && time() - filemtime($filename_cache) < $timeout)   {
            return true;
        return false;

I like to use magento cache

1 Answer 1


I'd choose a slightly different setup which will make the solution easier.

  • store your value as a config value in core_config_data using Magento\Framework\App\Config\Storage\WriterInterface
  • define a job in crontab.xml which overwrites this value once a day
  • when you want to access the value, simply access the configuration
  • 1
    I'd avoid storing the value in core_config_data. Those values are stored in config_cache. Magento\Framework\App\Config\ScopeConfigInterface method getValue() reads from cache. Writing to core_config_data won't flush the cache. Why not use Flag models. See: magegyver.de/using-flag-models-in-magento-2 Apr 15 at 10:21
  • Very nice, didn't know this existed Apr 18 at 7:23

Your Answer

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

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