Change cache path and get configuration variable to not use cache

This commit is contained in:
Michael RICOIS 2017-08-28 12:32:07 +02:00
parent b53ac563ad
commit 8d7ccb4d3f
2 changed files with 35 additions and 15 deletions

View File

@ -50,10 +50,24 @@ class privatesaleshomeModuleFrontController extends ModuleFrontController {
$this->setTemplate('privatesales-home.tpl');
// 12613 - Optimisation
$sale_cache = new SaleCache($this->context, "home", 7200, $news); // 2 Hours
if ($sale_cache->isCached($this->template)) {
$this->setCacheHtml($sale_cache->getCache());
return;
if(Configuration::get('PS_SMARTY_CACHE') == 1) {
$lifetime = 7200;
switch (Configuration::get('PS_SMARTY_FORCE_COMPILE')) {
case 0:
case 1:
$lifetime = 7200;
break;
case 2:
$lifetime = 0;
break;
}
if ($lifetime > 0) {
$sale_cache = new SaleCache($this->context, "home", $lifetime, $news);
if ($sale_cache->isCached($this->template)) {
$this->setCacheHtml($sale_cache->getCache());
return;
}
}
}
// 12613 - End optimisation

View File

@ -6,7 +6,7 @@ class SaleCache
private $smarty = null;
private $max_filemtime = 0;
private $template_path = '';
private $path_cache_file = '';
private $path_cache = '';
function __construct(Context $context, $cache_prefix, $lifetime, $is_sales_news = null)
{
@ -32,7 +32,13 @@ class SaleCache
$this->cache_id = md5("private_sales_".$cache_prefix."_".$d->format('Ymd'));
$this->max_filemtime = $d->getTimestamp() - $lifetime;
$this->path_cache_file = __DIR__.'/../cache/'.$this->cache_id;
$path_cache = _PS_CACHE_DIR_.'smarty/cache/privatesales';
if (!file_exists($path_cache)) {
mkdir($path_cache, 0755);
}
$this->path_cache_file = $path_cache.'/'.$this->cache_id;
$this->smarty = $context->smarty;
}