Exemple #1
0
  private void cacheAction(String cacheName, String cacheKey, Controller controller) {
    HttpServletRequest request = controller.getRequest();
    Map<String, Object> cacheData = new HashMap<String, Object>();
    for (Enumeration<String> names = request.getAttributeNames(); names.hasMoreElements(); ) {
      String name = names.nextElement();
      cacheData.put(name, request.getAttribute(name));
    }

    cacheData.put(renderKey, new RenderInfo(controller.getRender())); // cache RenderInfo
    CacheKit.put(cacheName, cacheKey, cacheData);
  }
Exemple #2
0
  public final void intercept(Invocation inv) {
    Controller controller = inv.getController();
    String cacheName = buildCacheName(inv, controller);
    String cacheKey = buildCacheKey(inv, controller);
    Map<String, Object> cacheData = CacheKit.get(cacheName, cacheKey);
    if (cacheData == null) {
      Lock lock = getLock(cacheName);
      lock.lock(); // prevent cache snowslide
      try {
        cacheData = CacheKit.get(cacheName, cacheKey);
        if (cacheData == null) {
          inv.invoke();
          cacheAction(cacheName, cacheKey, controller);
          return;
        }
      } finally {
        lock.unlock();
      }
    }

    useCacheDataAndRender(cacheData, controller);
  }