kohana为静态文件提供缓存机制
来源:互联网 发布:2015年度网络流行语 编辑:程序博客网 时间:2024/05/29 18:30
静态文件指的是: css/js/images
1. 匹配静态文件的方法
// classes/controller/base.phpclass Controller_Base extends Controller { // match static media filespublic function action_media(){// Generate and check the ETag for this file$this->request->check_cache(sha1($this->request->uri));// Get the file path from the request$file = $this->request->param('file');// Find the file extension$ext = pathinfo($file, PATHINFO_EXTENSION);// Remove the extension from the filename$file = substr($file, 0, -(strlen($ext) + 1));if ($file = Kohana::find_file('media', $file, $ext)){// Send the file content as the response$this->request->response = file_get_contents($file);}else{// Return a 404 status$this->request->status = 404;}// Set the content type for this extension$this->request->headers['Content-Type'] = File::mime_by_ext($ext);$this->request->headers['Content-Length'] = filesize($file);$this->request->headers['Last-Modified'] = date('r', filemtime($file));}}
重点,在上面的 $this->request->check_cache() 方法,注意是利用了 HTTP 头信息的 ETag 作校验。
2. 设置路由
// the media filesRoute::set('media', 'media(/<file>)', array('file' => '.+'))->defaults(array('controller' => 'base','action' => 'media','file' => NULL,));
3. 程序会自动把路径在 /media/ 下面的文件做缓存
10 0
- kohana为静态文件提供缓存机制
- nginx 静态文件缓存
- nginx 静态文件缓存
- JAVA静态文件缓存
- nginx 静态文件缓存
- nginx 静态文件缓存
- nginx缓存静态文件
- kohana
- 304 静态文件本地缓存
- apache配置静态文件缓存
- 静态文件的缓存处理
- kohana 伪静态的htaccess设置
- python编写简单服务器提供静态文件
- ci项目完成后隐藏入口文件,开启为静态,缓存
- PHP的文件缓存机制
- PHP的文件缓存机制
- 为应用提供文件的拖放功能
- Android客户端缓存机制(文字缓存和多媒体文件缓存)
- C++单例模板
- struts2的开发模式
- ”易“”难“计算器
- [ 生活 ] 如果你想走得更远!
- android手机获取手机号
- kohana为静态文件提供缓存机制
- 优雅的repo sync自动重试
- 题目1198:a+b
- C/C++语言 小程序 日历(万年历)
- [ javasript ] 从js小问题看大世界。
- Hibernate面试问题集锦: 概述
- postgresql 修改字段类型
- Hibernate使用技巧
- objc.io系列文章中文翻译汇总