Ejemplo n.º 1
0
    @Override
    public <T> T execute(final CachedHttpService cachedHttpService, final Parser parser) {
      T response = cachedHttpService.readFromCache(parser);
      if (response == null) {
        response = cachedHttpService.executeRequest(parser);
      } else {
        ExecutorUtils.execute(
            new Runnable() {

              @Override
              public void run() {
                try {
                  cachedHttpService.executeRequest(parser);
                } catch (Exception e) {
                  LoggerUtils.logHandledException(LOGGER, e);
                }
              }
            });
      }
      return response;
    }
Ejemplo n.º 2
0
    @Override
    public <T> T execute(final CachedHttpService cachedHttpService, final Parser parser) {
      Long originalTimeToLive = cachedHttpService.getTimeToLive();
      cachedHttpService.setTimeToLive(null);
      T response = cachedHttpService.readFromCache(parser);
      if (response == null) {
        response = cachedHttpService.executeRequest(parser);
      } else {
        cachedHttpService.setTimeToLive(originalTimeToLive);
        ExecutorUtils.execute(
            new Runnable() {

              @Override
              public void run() {
                try {
                  CachingStrategy.CACHE_FIRST.execute(cachedHttpService, parser);
                } catch (Exception e) {
                  LoggerUtils.logHandledException(LOGGER, e);
                }
              }
            });
      }
      return response;
    }