Opencart Cache details – remove while developing theme or module developer tips

Cache always make developer scream out in some case developers write the code correctly but they forget to clear the cache and they test the logic and data which they found it not working, as cache provides stale data and sense, they scream out loud, and after some hours of testing and logical changes, they remember to clear the cache 🙂 and they again scream out. The same case happens when I started to develop an OpenCart extension for OpenCart and I keep on testing the module but it did not show the changes as it is showing from the Cache folder which is in the storage/ folder that you keep outside of the public_html folder in your server. In OpenCart Version 2.*  it used to be in system/storage.

How to delete cache in OpenCart?

Login to the admin dashboard where you will see a gear icon for the Developer setting, and click it off the cache option available. For Opencart 4, you will see like below, where you can clear the cache and off it.

Opencart cache

Another place you can remove the cache is in the storage/ folder. You can find the storage folder location at config.php, look for the DIR_STORAGE constant where you can find the path of the storage folder.

DIR_STORAGE folder location

Go to that folder and inside find the cache/ folder and remove all other files except index.html. Likewise, go to upload/ folder and remove all except index.html, in this way you can remove the cache in Opencart for OCMOD.

How to remove the Vqmod cache?

To remove the VQMoD cache, go to vqmod/ and vqcache/ folder and remove all the files and folders except index.html.

Vqmod cache

How to remove the twig template cache in the OpenCart?

1. Click this setting icon on the dashboard
2. Then this popup shows then off the cache and clicks the refresh button

Another way is:

Open system\library\template\Twig\Environment.php, in the constructor:

public function __construct(Twig_LoaderInterface $loader = null, $options = array())
{
    if (null !== $loader) {
        $this->setLoader($loader);
    } else {
        @trigger_error('Not passing a Twig_LoaderInterface as the first constructor argument of Twig_Environment is deprecated since version 1.21.', E_USER_DEPRECATED);
    }

    $options = array_merge(array(
        'debug' => false,
        'charset' => 'UTF-8',
        'base_template_class' => 'Twig_Template',
        'strict_variables' => false,
        'autoescape' => 'html',
        'cache' => false,
        'auto_reload' => null,
        'optimizations' => -1,
    ), $options);

    $this->debug = (bool) $options['debug'];

Find the following line of code:

$this->debug = (bool) $options['debug'];

and change it to:

$this->debug = (bool) true;

Then your template file caching will be removed.

Another way to do this:

Open to system\library\template\Twig\Cache\Filesystem.php, and find the following lines of code

public function load($key)
{
    if (file_exists($key)) {
        @include_once $key;
    }
}

Comment out as in the following code:

public function load($key)
{
    // if (file_exists($key)) {
    //      @include_once $key;
    // }
}

This will remove the template cache of the twig and recreate it every time, once development is over you have to remove the comment.

Hope it will help your development time so that you don’t have to keep clearing the cache for each test. In this way, you clear the cache in Opencart, and Vqmod. Hope you liked this article, please subscribe to our YouTube Channel for Opencart video tutorials. You can also find us on Webocreation Twitter and Webocreation Facebook. Please let us know if you have any questions or concerns.

Previous article25 website security measures for eCommerce developer – Opencart
Next articleHow to show multiple flat rates shipping as per total? OpenCart 4 extension for free

6 COMMENTS

  1. Hi,

    I noticed a problem with v3.0.2.0 after creating a site on a2hosting. Anytime I create a folder or upload image , it won’t show up immediately. I have to logout and login again to see new folders or new images. It works without problem in local PC though. Is this something related to this caching?

  2. Hi,

    I noticed a problem with v3.0.2.0 after creating a site on a2hosting. Anytime I create a folder or upload image , it won’t show up immediately. I have to logout and login again to see new folders or new images. It works without problem in local PC though. Is this something related to this caching?

  3. Check this file:
    \system\library\template\twig.php

    // initialize Twig environment
    $config = array(
    ‘autoescape’ => false,
    ‘debug’ => false,
    ‘auto_reload’ => true,
    ‘cache’ => DIR_CACHE . ‘template/’
    );

    Coment out the cache line or change to false statment.
    // initialize Twig environment
    $config = array(
    ‘autoescape’ => false,
    ‘debug’ => false,
    ‘auto_reload’ => true,
    ‘cache’ => false
    );

LEAVE A REPLY

Please enter your comment!
Please enter your name here