code: long getCacheTimeInSec(HttpHeaders httpHeaders) {
      long cacheTimeInSec = 0;
      if (httpHeaders.getCacheControl() != null) {
        for (String arg : httpHeaders.getCacheControl().split(",")) {
          Matcher m = MAX_AGE_PATTERN.matcher(arg);
          if (m.matches()) {
            cacheTimeInSec = Long.parseLong(m.group(1));
            break;
          }
        }
      }
      if (httpHeaders.getAge() != null) {
        cacheTimeInSec -= httpHeaders.getAge();
      }
      return Math.max(0, cacheTimeInSec);
    }
docs: Gets the cache time in seconds. "max-age" in "Cache-Control" header and "Age" header are
  considered.
  
  @param httpHeaders the http header of the response
  @return the cache time in seconds or zero if the response should not be cached