On Friday, February 18, 2011 4:50:39 PM UTC+1, Luca wrote:
>
> My data access layer is on another tier, I can't use a ThreadLocal because 
> it can be executed on another thread or may be another node in the cluster.


But the RequestFactory request is executed all in one thread! What matters 
is that the "session cache" is scoped to the ServletRequest.

class MyLocator extends Locator<A, String> {

  @Override
  public A find(Class<? extends A> clazz, String id) {
    Map<String, A> cache = getCache();
    A ret = cache.get(id);
    if (ret == null) {
       ret = // get from whatever
       cache.put(id, ret);
    }
    return ret;
  }

  @SuppressWarnings("unchecked")
  private Map<String, A> getCache() {
    Map<String, A> cache = (Map<String, A>) 
RequestFactoryServlet.getThreadLocalRequest().getAttribute("cache");
    if (cache == null) {
      cache =new HashMap<String, A>();
      RequestFactoryServlet.getThreadLocalRequest().setAttribute("cache", 
cache);
    }
    return cache;
  }
...

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to