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

查看:173
本文介绍了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.

如果您要另外拒绝在本地保存数据(例如,出于安全原因或为了减少使用永远不会使用的信息填充本地缓存),则可以包含

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天全站免登陆