PDA

View Full Version : Ie7 caching problem



jlozina
12 May 2009, 3:54 PM
Hi

When using json to communicate with the server in Intenet Explorer 7 it caches the request so I dont get the latest data.
In Firefox the request gets processed every time.

Can someone let me know how to add a timestamp/parameter to the BasePagingLoader/json request so

http://localhost:8080/ProductApproval/controller.json?sortDir=NONE&start=0&limit=15

would appear as

http://localhost:8080/ProductApproval/controller.json?sortDir=NONE&start=0&limit=15&timestamp=1242172212329

Code is



ColumnModel cm = new ColumnModel(ApprovalProcessGridHelper.getColumnConfig());

// Incoming data model type
ModelType type = ApprovalProcessGridHelper.getModelType();
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, "/ProductApproval/controller.json");

HttpProxy proxy = new HttpProxy(builder);

// Reading Json data
JsonReader<PagingLoadConfig> reader = new JsonReader<PagingLoadConfig>(type) {
@Override
protected ListLoadResult newLoadResult(PagingLoadConfig loadConfig, List<ModelData> models) {
PagingLoadResult result = new BasePagingLoadResult(models, loadConfig.getOffset(), loadConfig.getLimit());

return result;
}
};
// Loader
final BasePagingLoader loader = new BasePagingLoader(proxy, reader);

loader.setRemoteSort(true);

// Store
ListStore<ModelData> store = new ListStore<ModelData>(loader);

// Grid
grid = new Grid(store, cm) {
//show loading... on startup
protected boolean loaded;
protected void onAttach() {
super.onAttach();
if (!loaded) {
loaded = true;

loader.load();
}
}
};

grid.setLoadMask(true);
grid.setTitle("Approval Process");
grid.setBorders(true);
grid.setEnableColumnResize(true);
grid.setStripeRows(true);
grid.setWidth(1200);
grid.setHeight(600);
grid.show();

jadrake75
13 May 2009, 9:18 AM
There are a few ways to do this.
(1) Set the request header indicating you need a non-cached request (preferred)
(2) add something to the query string that is "random" like a request count from the page. (this is similiar to a sessionID). If your request URL is "unique" IE will not cache it.

Method 2 will be more difficult for you since your request builder/proxy is setup for a store and without a subclass of a Proxy/Builder there is no way to do this "on the fly" (I created my own RestfulHttpProxy for processing some of the REST requests in which I needed to change the uripath.)

Your best option is to set headers on the RequestBuilder. There is a method "setHeader( )" on this class (see GWT Javadoc).

If you look at the HTTP 1.1 RFC: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
You will want to use the "Cache-Control" key. For no caching, you should try the

builder.setHeader("Cache-Control","no-cache");

Another option is the "must-revalidate". See the RFC for these definitions.

Finally, if you have control over the server, this is something you might want to do from that side. In my clients case, the client is not intelligent and simply processes what it is given. This this case, I have my server code setting the headers on the response such that the browser will always clear the data if appropriate.