Monday, December 7, 2009

Page level Caching of data

Instead of making the calls repeatedly to the server which might not change, we could cache the data in the scope. By doing something similar in the controller.
    final FacesContext context = FacesContext.getCurrentInstance();
    final HttpServletRequest request = (HttpServletRequest)
            context.getExternalContext().getRequest();
    String data = (String) request.getAttribute(“requestData”);
    if (data == null)
    {
       data = Go retrieve data from the server;
       request.setAttribute(“requestData”, data);
    }
In the above case we cache the data "requstData" in the requestMap and retrieve them. We do make call to the server for the data if the requestMap doesn't have the persisted data in it. This helps to reduce unnecessary calls to the server.

No comments:

Post a Comment