# node-webkit教程(14)禁用緩存
> 作者:玄魂
> 來源:[node-webkit教程(14)禁用緩存](http://www.cnblogs.com/xuanhun/p/4127262.html)
## 1.在開發者工具中禁用緩存

上面這張圖,是在node-webkit 中 在開發工具中配置禁用緩存的選項。
使用這個選項可以有效的禁用所有頁面緩存。
## 2. 在配置文件中,配置webkit 緩存禁用和啟用
```
{
"name": "name",
"description": "description",
"version": "0.1",
"main": "https://path-to-intranet-site/",
"node-remote": "https://path-to-intranet-site",
"webkit": {
"page-cache":false
},
"window": {
"show": true,
"toolbar": true,
"frame": true,
"position": "center",
"width": 800,
"height": 600,
"min_width": 220,
"min_height": 220
}
}
```
上面配置加粗的部分為禁用頁面緩存。但是經過我的實驗,仿佛頁面緩存和node-webkit本身的緩存是兩個不同的概念。
而且文檔上說默認情況下頁面緩存的值就是false。
## 3.臨時解決方案,不停的清除緩存
在開發過程中,我遇到了很多詭異的問題,都是由于node-webkit的緩存引起的。但是沒有找到禁用緩存的api,能起到像方案1那樣在開發者工具中禁用緩存的效果。
但是找到了清除緩存的api gui.App.clearCache();
要想達到禁用的效果,必須不停的清空緩存。
-----------------------幾天之后-------------------
## 4. 使用Window.disableCache(bool) api
我在github上向node-webkit作者提交了關于清除緩存的bug。作者響應很迅速,在12月2號編譯的 的版本中
([http://dl.node-webkit.org/live-build/12-02-2014/831a6af-dad58ea-344f210-f2f89e2-d9a9d39-cdd879e/](http://dl.node-webkit.org/live-build/12-02-2014/831a6af-dad58ea-344f210-f2f89e2-d9a9d39-cdd879e/))
提供了Window.disableCache(bool) api,用來禁用緩存。
現在再也不用糾結了。
- 中文 Wiki
- 支持列表
- 開始nw.js
- package.json
- 中文教程
- node-webkit學習(1)hello world
- node-webkit學習(2)基本結構和配置
- node-webkit學習(3)Native UI API概覽
- node-webkit學習(4)Native UI API 之window
- node-webkit教程(5)Native UI API 之Frameless window
- node-webkit教程(6)Native UI API 之Menu(菜單)
- node-webkit教程(7)Platform Service之APP
- node-webkit教程(8)Platform Service之Clipboard
- node-webkit教程(9)native api 之Tray(托盤)
- node-webkit教程(10)Platform Service之File dialogs
- node-webkit教程(11)Platform Service之shell
- node-webkit教程(12)全屏
- node-webkit教程(13)gpu支持信息查看
- node-webkit教程(14)禁用緩存
- node-webkit教程(15)當圖片加載失敗的時候
- node-webkit教程(16)調試typescript