Disable cache in ExtLib REST control (which uses dojox.data.JsonRestStore)

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-10 23:59:33

问题


In my XPage I have a xe:djxDataGrid (dojox.grid.datagrid) which uses xe:restService which seems to use dojox.data.JsonRestStore.

Everything works fine without proxy but my client accesses the application via a proxy because of corporate policy. After a user updates data in the DataGrid it shows old values when accessed behind the proxy.

When the REST Control/JsonRestStore sends an ajax GET request to get data, there is no Cache-Control parameter in request headers. And Domino does not place Expires parameter in the reponse headers. I believe that's why the old version of the GET request gets cached by the proxy.

We have tried to disable cache in browsers but that does not help which indicates the proxy is caching the requests.

I believe this could be solved either by:

  1. Setting Cache-Control parameter in request headers OR
  2. Setting Expires parameter in response headers

But I haven't found a way to set either of these. For the XPage Domino sets Expires:-1 response header but not for the ajax GET request which is:

/mypage.xsp/?$$viewid=!ddrg6o7q1z!&$$axtarget=view:_id1:_id2:callback1:restService1

This returns the JSON data to JsonRestStore and gets cached by the proxy.

One options is to try to get an exception to the proxy so requests to this site would bypass the proxy cache. But exceptions are generally not easy to get thru.

Any ideas? Thanks.

Update1

My colleque suggested that I could intercept the xhr GET requests made by dojox.data.JsonRestStore and add a time parameter to the URL to prevent cache. Here is my question about that:

Prevent cache in every Dojo xhr request on page

Update2

@SvenHasselbach has a great solution for preventing cache for all xhrs:

http://openntf.org/XSnippets.nsf/snippet.xsp?id=cache-prevention-for-dojo-xhr-requests

It seems to work perfectly, &dojo.preventCache= parameter is added to the URLs and the requests seem to return correct JSON also with this parameter. But the DataGrid stops working when I use that code. Every xhr causes this error:

Tried with Firefox and Chrome. The first page of data still loads because xhr interception is not yet in place but the subsequent pages show only "..." in each cell.


回答1:


The solution is Sven Hasselbach's code in the comment section of Julian Buss's blog which needs to be slightly modified.

I changed xhrPost to xhrGet and did not place the code to dojo.addOnLoad. When placed there it was not effective in the first XHR by the DataGrid/Store.

I also removed the headers modification because it overrides existing headers. When the REST control requests data from server with xhrGet the URL is always the same and rows requested are in HTTP header like this:

Range: items=0-9

This (and other) headers disappear when the original code is used. To just add headers we would have take the existing headers from args and append to them. I didn't see a need for that because it should be enough to add the parameter in the URL. Here is the extremely simple code I'm using:

if( !(dojo._xhrGet )) {
 dojo._xhrGet = dojo.xhrGet;
}

dojo.xhrGet = function (args) {
 args['preventCache'] = true;
 return dojo._xhrGet(args);
}

Now I'm getting all rows and all XHR Get URLs have &dojo.preventCache= parameter which is exactly what I wanted. Next we'll test in customer environment to see if this solves their problem.

Update

As Julian points out in his blog I could also use a Web Site Rule to set Expires or cache-control http response headers.

Update

The customer reports it's working now for them!



来源:https://stackoverflow.com/questions/14519695/disable-cache-in-extlib-rest-control-which-uses-dojox-data-jsonreststore

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!