Jump to content

enable/disable cache by php script


Geo3010

Recommended Posts

I need to temporary disable the cache for the time needed for a script to run.

 

At the moment I just manually disable the cache via admin pannel -> Advanced parameters -> Performance: Use cache yes/no, before to run the script and then reenable it when it's done.

 

I want to automate this disabling the cache at the beginning of the script and reenabling it at the end.

(the script must run in cron)

 

I've tried something I've found in AdminPerformanceController: 

/* DISABLE CACHE */
$prev_settings = file_get_contents(_PS_ROOT_DIR_.'/config/settings.inc.php');
$new_settings = $prev_settings;
$cache_active = 0; // 1 to enable
$new_settings = preg_replace('/define\(\'_PS_CACHE_ENABLED_\', \'([01]?)\'\);/Ui', 'define(\'_PS_CACHE_ENABLED_\', \''.(int)$cache_active.'\');', $new_settings);
if(copy(_PS_ROOT_DIR_.'/config/settings.inc.php', _PS_ROOT_DIR_.'/config/settings.old.php') && (bool)file_put_contents(_PS_ROOT_DIR_.'/config/settings.inc.php', $new_settings)) {
    error_log("Cache disabled");
} else {
    error_log("Seems that the settings file cannot be overwritten");
    exit;
}

But it's not enough, I think it's missing some kind of settings reload action or similar...

 

Any idea?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...