title: Enabling caching for GWT RPC asynchronous calls
body: <p>I'm thinking of introducing some kind of caching mechanism (like HTML5 local storage) to avoid frequent RPC calls whenever possible. I would like to get feedback on how caching can be introduced in the below piece of code without changing much of the architecture (like using gwt-dispatch).</p>
  
  <pre class="lang-java prettyprint-override"><code>void getData() {
  
      /* Loading indicator code skipped */
  
      /* Below is a gwt-maven plugin generated singleton for SomeServiceAsync */
      SomeServiceAsync.Util.getInstance().getDataBySearchCriteria(searchCriteria, new AsyncCallback&lt;List&lt;MyData&gt;&gt;() {
  
          public void onFailure(Throwable caught) {
              /* Loading indicator code skipped */
              Window.alert("Problem : " + caught.getMessage());
          }
  
          public void onSuccess(List&lt;MyData&gt; dataList) {
              /* Loading indicator code skipped */
          }
      });
  }
  </code></pre>
  
  <p>One way I can think of to deal with this is to have a custom MyAsyncCallback class defining onSuccess/onFailure methods and then do something like this -</p>
  
  <pre class="lang-java prettyprint-override"><code>void getData() {
  
      AsyncCallback&lt;List&lt;MyData&gt;&gt; callback = new MyAsyncCallback&lt;List&lt;MyData&gt;&gt;;
  
      // Check if data is present in cache
      if(cacheIsPresent)
          callback.onSuccess(dataRetrievedFromCache);
      else
      //  Call RPC and same as above and of course, update cache wherever appropriate
  }
  </code></pre>
  
  <p>Apart from this, I had one more question. What is the maximum size of storage available for LocalStorage for popular browsers and how do the browsers manage the LocalStorage for different applications / URLs? Any pointers will be appreciated.    </p>