Package br.com.caelum.vraptor.actioncache.events

Source Code of br.com.caelum.vraptor.actioncache.events.ExecuteIfNoCache

package br.com.caelum.vraptor.actioncache.events;

import javax.enterprise.inject.Vetoed;

import br.com.caelum.vraptor.actioncache.ActionCache;
import br.com.caelum.vraptor.actioncache.ActionCacheEntry;
import br.com.caelum.vraptor.actioncache.CacheKey;
import br.com.caelum.vraptor.actioncache.Cached;
import br.com.caelum.vraptor.actioncache.CachedMethodExecuted;
import br.com.caelum.vraptor.actioncache.RequestHeaders;
import br.com.caelum.vraptor.controller.ControllerMethod;

@Vetoed
public class ExecuteIfNoCache {

  private ControllerMethod controllerMethod;
  private ActionCache actionCache;
  private RequestHeaders requestHeaders;

  public ExecuteIfNoCache(ControllerMethod controllerMethod, ActionCache actionCache,
      RequestHeaders requestHeaders) {
    super();
    this.controllerMethod = controllerMethod;
    this.actionCache = actionCache;
    this.requestHeaders = requestHeaders;
  }

  public <ParamterType> void execute(Runnable runnable) {
    CachedMethodExecuted cachedMethodExecuted = new CachedMethodExecuted(controllerMethod);
    Cached cached = cachedMethodExecuted.getCached();
    if (cached == null) {
      runnable.run();
      return;
    }
    ActionCacheEntry body = actionCache.fetch(new CacheKey(cached, requestHeaders));
    if (body == null) {
      runnable.run();
    }
  }

}
TOP

Related Classes of br.com.caelum.vraptor.actioncache.events.ExecuteIfNoCache

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.