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:
- Setting
Cache-Control
parameter in request headers OR - 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.
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
toxhrGet
and did not place the code todojo.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 withxhrGet
the URL is always the same and rows requested are in HTTP header like this: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: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
orcache-control
http response headers.Update
The customer reports it's working now for them!