2015-12-21 21 views
0

我如何清除我的圖案網址(動態網址)的緩存?
喜歡,/assets/js/@jsname.js ...

我不想等到緩存過期後,我想要它,立即在我更新我的數據庫的東西后。
如何強制清空緩存的動態網址在無脂框架?

They said要清除數據庫,您需要指定它的密鑰。而且我不知道我應該爲重點:(

這裏進入我的代碼:

\F3::route("GET @virtualasset: /assets/img/@link/@[email protected]@type", "Control\\Imager->akses", 3600 * 24 * 7); // cache seminggu :3 

回答

0

HTTP響應使用以下key緩存:hash(VERB URI).url

所以,如果你想刷新assets/js/foo.js,你必須做的:

$hash=$f3->hash('GET /assets/js/foo.js'); 
$cache->clear($hash.'.url'); 

但是,這是一個黑客位的因爲這個密鑰沒有記錄,將來可能會改變。

另外,您需要記住的是,參數$ttl不僅觸發服務器緩存,還會觸發客戶端緩存。這意味着您需要實現緩存驅動程序來刷新客戶端緩存。像assets/js/foo.js?v=3

您可以考慮直接在您的控制器類中實現緩存。這會給你更多的靈活性。

+0

哇!好吧...我會嘗試! – Chris

0

我使用這條路線:

GET | HEAD /資產/ @文件夾/ @型/ V- @版本/ * =控制器\資產 - >發送,3600

我控制器:

namespace controllers; 
class Assets { 

    private $paths; 
    private $types = ['css', 'js', 'i', 'fonts', 'files', 'icons']; 
    private $dontminify = ['i', 'fonts', 'files', 'icons']; 


    public function __construct() { 
     $this->fw = \Base::instance(); 
     $this->paths['app'] = '../app/views/site_tpl/assets/'; 
     $this->paths['core'] = '../core/views/default/assets/'; 
    } 

    public function send() { 

     if (in_array($this->fw->get('PARAMS.folder'), array_keys($this->paths)) 
      && in_array($this->fw->get('PARAMS.type'), $this->types)) 
     { 
      $folder = $this->paths[$this->fw->get('PARAMS.folder')]; 
      $type = $this->fw->get('PARAMS.type'); 
      if (in_array($type, $this->dontminify)) { 
       $file = $folder . $type . '/' . $this->fw->pop('PARAMS'); 
       if (\Web::instance()->send($file)) { 
        return true; 
       } 
      } else { 
       $this->fw->set('UI', $folder . $type . '/'); 
       $file = $this->fw->pop('PARAMS'); 
       if (file_exists($this->fw->get('UI') . $file)) { 
        if (!$this->fw->exists('GET.dontminify')) { 
         echo \Web::instance()->minify($file); 
         return true; 
        } elseif (\Web::instance()->send($this->fw->get('UI') . $file)) { 
         return true; 
        } 
       } 
      } 
     } 
     $this->fw->error(404); 
    } 

} 

所以,當我想更新文件的版本,我寫somethong這樣的:

<script src="/assets/app/js/v-20160205/main.js"></script>