2015-12-21 41 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>