[*] MO: Add smarty cache on some modules
This commit is contained in:
@@ -598,9 +598,12 @@ class CustomerCore extends ObjectModel
|
||||
|
||||
public static function getGroupsStatic($id_customer)
|
||||
{
|
||||
if (!Group::isFeatureActive() || $id_customer == 0)
|
||||
if (!Group::isFeatureActive())
|
||||
return array(Configuration::get('PS_CUSTOMER_GROUP'));
|
||||
|
||||
if ($id_customer == 0)
|
||||
self::$_customer_groups[$id_customer] = array((int)Configuration::get('PS_UNIDENTIFIED_GROUP'));
|
||||
|
||||
if (!isset(self::$_customer_groups[$id_customer]))
|
||||
{
|
||||
self::$_customer_groups[$id_customer] = array();
|
||||
|
||||
@@ -1830,6 +1830,7 @@ exit;
|
||||
self::$_caching = (int)$smarty->caching;
|
||||
$smarty->force_compile = 0;
|
||||
$smarty->caching = (int)$level;
|
||||
$smarty->cache_lifetime = 31536000; // 1 Year
|
||||
}
|
||||
|
||||
public static function restoreCacheSettings(Context $context = null)
|
||||
|
||||
@@ -1582,11 +1582,18 @@ abstract class ModuleCore
|
||||
{
|
||||
return Module::_isTemplateOverloadedStatic($this->name, $template);
|
||||
}
|
||||
|
||||
protected function getCacheId($name = null)
|
||||
{
|
||||
if ($name === null)
|
||||
$name = $this->name;
|
||||
return $name.'|'.(int)$this->context->shop->id.'_'.(int)Group::getCurrent()->id.'_'.(int)$this->context->language->id;
|
||||
}
|
||||
|
||||
public function display($file, $template, $cacheId = null, $compileId = null)
|
||||
{
|
||||
if (($overloaded = Module::_isTemplateOverloadedStatic(basename($file, '.php'), $template)) === null)
|
||||
$result = Tools::displayError('No template found for module').' '.basename($file, '.php');
|
||||
return Tools::displayError('No template found for module').' '.basename($file, '.php');
|
||||
else
|
||||
{
|
||||
$this->smarty->assign(array(
|
||||
@@ -1594,16 +1601,22 @@ abstract class ModuleCore
|
||||
'module_template_dir' => ($overloaded ? _THEME_DIR_ : __PS_BASE_URI__).'modules/'.basename($file, '.php').'/'
|
||||
));
|
||||
|
||||
if ($cacheId !== null)
|
||||
Tools::enableCache();
|
||||
|
||||
$smarty_subtemplate = $this->context->smarty->createTemplate(
|
||||
$this->getTemplatePath($template),
|
||||
$cacheId,
|
||||
$compileId,
|
||||
$this->smarty
|
||||
);
|
||||
|
||||
$result = $smarty_subtemplate->fetch();
|
||||
|
||||
if ($cacheId !== null)
|
||||
Tools::restoreCacheSettings();
|
||||
|
||||
return $result;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1635,7 +1648,11 @@ abstract class ModuleCore
|
||||
{
|
||||
$context = Context::getContext();
|
||||
|
||||
return $context->smarty->isCached($this->getTemplatePath($template), $cacheId, $compileId);
|
||||
Tools::enableCache();
|
||||
$is_cached = $context->smarty->isCached($this->getTemplatePath($template), $cacheId, $compileId);
|
||||
Tools::restoreCacheSettings();
|
||||
|
||||
return $is_cached;
|
||||
}
|
||||
|
||||
protected function _clearCache($template, $cache_id = null, $compile_id = null)
|
||||
|
||||
Reference in New Issue
Block a user