2017-02-08 53 views
3

我搜索了很多這個問題,我沒有找到Prestashop 1.6的正確答案,我做了一個腳本來清除Prestashop緩存,smarty緩存, 我從代碼從adminPerformances控制器,Prestashop清除緩存哪些文件夾受影響

Tools::clearSmartyCache(); 
Tools::clearXMLCache(); 
Media::clearCache(); 
Tools::generateIndex(); 

,我讀了它清除從/緩存/智者/高速緩存,但在表演頁面執行在清除緩存的腳本或點擊時,它不會從該文件夾中刪除子文件夾。 任何人都知道'清除緩存'會影響哪些文件夾/文件。

謝謝。

+0

在我的情況下(PS 1.6.1.6),它只刪除一些文件夾,但不是全部文件夾。在'cache/smarty/compile'中,當你調用'Tools :: clearSmartyCache();' –

回答

1

Prestashop使用一個名爲Lazy Cache的系統。

這裏是/classes/SmartyCustom CLASSE的clearAllCacheclearCache方法:

public function clearAllCache($exp_time = null, $type = null) 
{ 
    Db::getInstance()->execute('REPLACE INTO `'._DB_PREFIX_.'smarty_last_flush` (`type`, `last_flush`) VALUES (\'template\', FROM_UNIXTIME('.time().'))'); 
    return $this->delete_from_lazy_cache(null, null, null); 
} 

public function clearCache($template_name, $cache_id = null, $compile_id = null, $exp_time = null, $type = null) 
{ 
    return $this->delete_from_lazy_cache($template_name, $cache_id, $compile_id); 
} 

public function delete_from_lazy_cache($template, $cache_id, $compile_id) 
{ 
    if (!$template) { 
     return Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'smarty_lazy_cache`', false); 
    } 

    $template_md5 = md5($template); 
    $sql   = 'DELETE FROM `'._DB_PREFIX_.'smarty_lazy_cache` 
         WHERE template_hash=\''.pSQL($template_md5).'\''; 

    if ($cache_id != null) { 
     $sql .= ' AND cache_id LIKE "'.pSQL((string)$cache_id).'%"'; 
    } 

    if ($compile_id != null) { 
     if (strlen($compile_id) > 32) { 
      $compile_id = md5($compile_id); 
     } 
     $sql .= ' AND compile_id="'.pSQL((string)$compile_id).'"'; 
    } 
    Db::getInstance()->execute($sql, false); 
    return Db::getInstance()->Affected_Rows(); 
} 

正如你可以看到,緩存文件在數據庫表下的索引smarty_lazy_cache。並且緩存文件不會被刪除,只能從表中取消索引。

+0

時,你會看到'last_flush'是否被更新?這是用於mysql還是文件系統緩存? –

+0

用於Smarty文件系統緩存。正如您在表「smaty_lazy_cache」中所看到的,「filepath」列包含緩存文件的路徑。 –

+0

我看到表,它是空的,我意外刪除了緩存/ smarty /文件夾,並重新創建它,但總是空的你有解決方案嗎? 謝謝 –

0

即使它沒有緩存選項仍然在fowllowing文件夾中創建緩存文件:

/cache/smarty/cache 
/cache/smarty/compile 

我認爲應該Smarty_Internal_Utility::clearCompiledTemplate刪除這些文件。這被稱爲Tools::clearSmartyCache()

但無論如何,最讓我感到困擾的是,甚至沒有緩存選項和強制編譯,大多數時候我需要手動清除緩存。通常通過刪除我上面提到的文件夾(速度更快,特別是在本地的虛擬機上)。 這個問題在1.7中仍然是一個「bug」。

說到1.7,高速緩存在/app/cache,有一個用於dev,一個用於prod。它甚至是緩存翻譯,class_index.php,以及比1.6緩存更多的東西。

+0

正如我在我的問題中寫道,我嘗試了Tools :: clearSmartyCache();但它並沒有清除/ cache/smarty/cache和/ cache/smarty/compile子文件夾 –

0

據我們所知,唯一受管理面板清除緩存時受到影響的文件夾。

/cache/smarty/compile 

請讓我們知道,如果我們錯了。

相關問題