jqGrid 数据存储在浏览器缓存中? [英] jqGrid data stored in browser cache?

查看:11
本文介绍了jqGrid 数据存储在浏览器缓存中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

jqGrid 是否在文件系统上存储网格数据?如果是这样,您是否需要清除浏览器的缓存才能将其删除?

Does jqGrid store grid data on the file system? If so, do you need to clear the browser's cache to remove it?

或者它只是由 JavaScript(和浏览器)存储在内存中?只是关闭浏览器会删除数据吗?

Or is it just stored in memory by JavaScript (and the browser)? Would just closing your browser remove the data?

这些问题的答案是否会根据您是否使用 loadOnce 而改变?

Do the answers to these questions change depending on whether you are using loadOnce?

推荐答案

默认情况下,从服务器加载的数据(JSON 或 XML 数据)将保存在浏览器缓存中,但不使用下一个请求.原因是每个默认 jqGrid 实现了 ajax 请求的相同行为,例如 jQuery.ajax.这意味着所有请求都有一个附加参数nd,例如nd=1286296925096,它是时间戳.它使所有 GET 请求的 URL 唯一,因此本地保存的数据不会被使用两次.因此,如果您希望 jqGrid 不使用本地浏览器缓存中的数据,您无需执行任何操作.

Per default the data loaded from the server (JSON or XML data) will be saved in the browser cache, but not used at the next request. The reason is that per default jqGrid implement the same behavior of ajax requests like cache:false parameter of jQuery.ajax. It means that all requests has an additional parameter nd like nd=1286296925096 which is the timestamp. It makes the URL of all GET requests unique and so the local saved data will not used twice. So if you want that jqGrid not use the data from the local browser cache you need to do nothing.

如果您还想拒绝在本地保存数据(例如,出于安全原因或减少使用永远不会使用的信息填充本地缓存),您可以包括 no-store 指令.

If you want additionally deny saving the data locally (for example because of security reason or to reduce filling of the local cache with the information which will never used) you can include no-store directive in the HTTP header of the server response.

如果您确实想缓存服务器请求并使用数据,您应该 prmNames: { nd:null} jqGrid 选项.然后可以从本地浏览器缓存中获取来自下一个请求的数据.如果您这样做,我建议您在服务器响应的 HTTP 标头中包含 Cache-Control 指令强制使用您需要的缓存行为.例如,我个人使用 Cache-Control: max-age=0 并将 ETag 与发送数据的哈希一起使用.所以所有 ajax 请求将被发送到服务器以重新验证本地缓存.所有请求将自动包含 If-None-Match HTTP 标头和本地缓存数据的 ETag.如果数据没有改变,服务器可以回答 HTTP/1.1 304 Not Modified 没有正文,而不是 HTTP/1.1 200 OK 正文有数据.响应 HTTP/1.1 304 Not Modified 允许浏览器使用本地缓存.

If you do want to cache the server requests and use the data you should prmNames: { nd:null} jqGrid option. Then the data from the next requests could be get from the local browser cache. If you do this I'll recommend you include in the HTTP header of the server response the Cache-Control directives which force to use the caching behavior which you need. For example I use personally Cache-Control: max-age=0 and use ETag with the hash from the data sent. So all ajax requests will be sent to the server to revalidate the local cache. All the requests will be automatically contain If-None-Match HTTP header with the ETag of the data from the local cache. If the data are not changed the server can answer with the response HTTP/1.1 304 Not Modified having no body instead of HTTP/1.1 200 OK with the body having the data. The response HTTP/1.1 304 Not Modified allows the browser to use the local cache.

更新:我另外使用 Cache-Control: private 关闭代理上的数据缓存并声明数据可以缓存,但不能与其他人共享用户.

UPDATED: I use additionally Cache-Control: private which switch off caching the data on the proxy and declare that the data could be cached, but not shared with another users.

如果您想了解有关 HTTP 标头的缓存控制的更多信息,我建议您阅读以下 缓存教程.

If you want read more about caching control with respect of HTTP headers I'll recommend you to read the following Caching Tutorial.

这篇关于jqGrid 数据存储在浏览器缓存中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆