clearCache() public method

Empty cache for a specific template
public clearCache ( string $template_name, string $cache_id = null, string $compile_id = null, integer $exp_time = null, string $type = null ) : integer
$template_name string template name
$cache_id string cache id
$compile_id string compile id
$exp_time integer expiration time
$type string resource type
return integer number of cache files deleted
 /**
  * Expires the cache
  *
  * @param boolean $expireAll expire the whole cache
  */
 public function CacheExpire($expireAll = false)
 {
     if ($expireAll) {
         $this->tpl->clearAllCache();
         return;
     }
     if (!$this->project) {
         return;
     }
     $epoch = $this->GetProject()->GetEpoch();
     if (empty($epoch)) {
         return;
     }
     $age = $this->GetProject()->GetAge();
     $this->tpl->clearCache(null, $this->GetCacheKeyPrefix(), null, $age);
     $this->tpl->clearCache('projectlist.tpl', $this->GetCacheKeyPrefix(false), null, $age);
 }
Example #2
0
 public function clearCurrentCache()
 {
     $tpl = system::param("page");
     if ($tpl) {
         $tpl = "{$tpl}.tpl";
         if (system::param("templateBase")) {
             $tpl = "extends:" . system::param("templateBase") . "|{$tpl}";
         }
     } else {
         $tpl = null;
     }
     $cacheID = $this->getCacheID();
     if ($cacheID) {
         parent::clearCache(null, $cacheID);
     } else {
         parent::clearCache($tpl);
     }
 }
Example #3
0
function clearCacheFiles(Smarty $smarty, $cache_id = 0, $table = '', $table_id = 0, $link = '')
{
    $cache_data = array();
    // Удаление файлов кэша по ID
    if ((int) $cache_id > 0) {
        $query = 'CALL get_table_row_by_id(:current_table, :id_value)';
        $params = array(':current_table' => PREF . 'cached_files', ':id_value' => $cache_id);
        $tmp = PdoWrap::select($query, $params);
        $cache_data = array_merge($cache_data, $tmp);
        $query = 'CALL delete_table_row_by_field(:current_table, :table_cell, :cell_value)';
        $params = array(':current_table' => PREF . 'cached_files', ':table_cell' => 'id', ':cell_value' => $cache_id);
        PdoWrap::execute($query, $params);
    }
    // Удаление файлов кэша по ID таблицы
    if (!empty($table) && (int) $table_id > 0) {
        $query = 'SELECT * FROM `' . PREF . 'cached_files` WHERE `table_name` = :table_name AND `table_id` = :table_id';
        $params = array(':table_name' => $table, ':table_id' => $table_id);
        $tmp = PdoWrap::select($query, $params);
        $cache_data = array_merge($cache_data, $tmp);
        $query = 'DELETE FROM `' . PREF . 'cached_files` WHERE `table_name` = :table_name AND `table_id` = :table_id';
        $params = array(':table_name' => $table, ':table_id' => $table_id);
        PdoWrap::execute($query, $params);
    }
    // Удаление файлов кэша по всей таблице
    if (!empty($table) && (int) $table_id == 0) {
        $query = 'SELECT * FROM `' . PREF . 'cached_files` WHERE `table_name` = :table_name';
        $params = array(':table_name' => $table);
        $tmp = PdoWrap::select($query, $params);
        $cache_data = array_merge($cache_data, $tmp);
        $query = 'DELETE FROM `' . PREF . 'cached_files` WHERE `table_name` = :table_name';
        $params = array(':table_name' => $table);
        PdoWrap::execute($query, $params);
    }
    // Удаление файлов кэша по ссылке
    if (!empty($link)) {
        $query = 'SELECT * FROM `' . PREF . 'cached_files` WHERE `link` LIKE :link';
        $params = array(':link' => '%' . $link . '%');
        $tmp = PdoWrap::select($query, $params);
        $cache_data = array_merge($cache_data, $tmp);
        $query = 'DELETE FROM `' . PREF . 'cached_files` WHERE `link` LIKE :link';
        $params = array(':link' => '%' . $link . '%');
        PdoWrap::execute($query, $params);
    }
    for ($i = 0; $i < count($cache_data); $i++) {
        $smarty->clearCache($cache_data[$i]['template'], $cache_data[$i]['id']);
    }
}
Example #4
0
 /**
  * Empty cache for a specific template
  *
  * This is just a pass-through wrapper with a warning since this method previously existed
  * only in XoopsTpl, but now is also a regular Smarty method.
  *
  * clearModuleCompileCache() is the replacement for the old clearCache
  *
  * @param  string  $template_name template name
  * @param  string  $cache_id      cache id
  * @param  string  $compile_id    compile id
  * @param  integer $exp_time      expiration time
  * @param  string  $type          resource type
  *
  * @return integer number of cache files deleted
  */
 public function clearCache($template_name, $cache_id = null, $compile_id = null, $exp_time = null, $type = null)
 {
     \Xoops::getInstance()->deprecated('XoopsTpl::clearCache() is potentially ambiguous');
     return parent::clearCache($template_name, $cache_id, $compile_id, $exp_time, $type);
 }
Example #5
0
 /**
  * Handle the lazy template cache invalidation
  *
  * @param  string  $template template name
  * @param  string  $cache_id      cache id
  * @param  string  $compile_id    compile id
  */
 public function check_template_invalidation($template, $cache_id, $compile_id)
 {
     static $last_flush = null;
     if (!file_exists($this->getCacheDir() . 'last_template_flush')) {
         @touch($this->getCacheDir() . 'last_template_flush', time());
     } elseif (defined('_DB_PREFIX_')) {
         if ($last_flush === null) {
             $sql = 'SELECT UNIX_TIMESTAMP(last_flush) as last_flush FROM `' . _DB_PREFIX_ . 'smarty_last_flush` WHERE type=\'template\'';
             $last_flush = Db::getInstance()->getValue($sql, false);
         }
         if ((int) $last_flush && @filemtime($this->getCacheDir() . 'last_template_flush') < $last_flush) {
             @touch($this->getCacheDir() . 'last_template_flush', time());
             parent::clearAllCache();
         } else {
             if ($cache_id !== null && (is_object($cache_id) || is_array($cache_id))) {
                 $cache_id = null;
             }
             if ($this->is_in_lazy_cache($template, $cache_id, $compile_id) === false) {
                 // insert in cache before the effective cache creation to avoid nasty race condition
                 $this->insert_in_lazy_cache($template, $cache_id, $compile_id);
                 parent::clearCache($template, $cache_id, $compile_id);
             }
         }
     }
 }
Example #6
0
 public function clear_cache($template = null, $cache_id = null, $compile_id = null, $exp_time = null)
 {
     if (is_null($template)) {
         $template = CONTROLLER_NAME . '/' . ACTION_NAME . C('view_suffix');
     } elseif (strstr($template, '.')) {
         //直接使用模板路径
     } elseif (strstr($template, ':')) {
         $template = str_replace(':', '/', $template);
         $template = $template . C('view_suffix');
     } else {
         $template = CONTROLLER_NAME . '/' . $template . C('view_suffix');
     }
     return parent::clearCache($template, $cache_id, $compile_id, $exp_time);
 }
Example #7
0
 public function clearCache($template, $cache_id = null)
 {
     return $this->smarty->clearCache($template, $cache_id);
 }
Example #8
0
 public function clearCache($template_name, $cache_id = null, $compile_id = null, $exp_time = null, $type = null)
 {
     $template_name .= '.tpl';
     $this->smarty->clearCache($template_name, $cache_id, $compile_id, $exp_time, $type);
 }