/** * @return Consolidated ttl in milliseconds or -1. */ public long getCacheTtl() { long expiration = getCacheExpiration(); if (expiration != -1) { return expiration - getTimeSource().currentTimeMillis(); } return -1; }
/** * @return Consolidated ttl in milliseconds or -1. */ public long getCacheTtl() { long expiration = getCacheExpiration(); if (expiration != -1) { return expiration - getTimeSource().currentTimeMillis(); } return -1; }
/** * @return Consolidated ttl in milliseconds or -1. */ public long getCacheTtl() { long expiration = getCacheExpiration(); if (expiration != -1) { return expiration - getTimeSource().currentTimeMillis(); } return -1; }
/** * Tries to find a valid date from the input headers. * * @return The value of the date header, in milliseconds, or -1 if no Date could be determined. */ private static long getAndUpdateDate(Multimap<String, String> headers) { // Validate the Date header. Must conform to the HTTP date format. long timestamp = -1; long currentTime = getTimeSource().currentTimeMillis(); Collection<String> dates = headers.get(HttpHeaders.DATE); if (!dates.isEmpty()) { Date d = DateUtil.parseRfc1123Date(dates.iterator().next()); if (d != null) { timestamp = d.getTime(); } } if (timestamp == -1) { timestamp = currentTime; headers.replaceValues(HttpHeaders.DATE, ImmutableList.of(DateUtil.formatRfc1123Date(timestamp))); } return timestamp; }
/** * Tries to find a valid date from the input headers. * * @return The value of the date header, in milliseconds, or -1 if no Date could be determined. */ private static long getAndUpdateDate(Multimap<String, String> headers) { // Validate the Date header. Must conform to the HTTP date format. long timestamp = -1; long currentTime = getTimeSource().currentTimeMillis(); Collection<String> dates = headers.get("Date"); if (!dates.isEmpty()) { Date d = DateUtil.parseRfc1123Date(dates.iterator().next()); if (d != null) { timestamp = d.getTime(); if (Math.abs(currentTime - timestamp) > responseDateDriftLimit) { // Do not trust the date from response if it is too old (server time out of sync) timestamp = -1; } } } if (timestamp == -1) { timestamp = currentTime; headers.replaceValues("Date", ImmutableList.of(DateUtil.formatRfc1123Date(timestamp))); } return timestamp; }
/** * Tries to find a valid date from the input headers. * * @return The value of the date header, in milliseconds, or -1 if no Date could be determined. */ private static long getAndUpdateDate(Multimap<String, String> headers) { // Validate the Date header. Must conform to the HTTP date format. long timestamp = -1; long currentTime = getTimeSource().currentTimeMillis(); Collection<String> dates = headers.get("Date"); if (!dates.isEmpty()) { Date d = DateUtil.parseRfc1123Date(dates.iterator().next()); if (d != null) { timestamp = d.getTime(); if (Math.abs(currentTime - timestamp) > responseDateDriftLimit) { // Do not trust the date from response if it is too old (server time out of sync) timestamp = -1; } } } if (timestamp == -1) { timestamp = currentTime; headers.replaceValues("Date", ImmutableList.of(DateUtil.formatRfc1123Date(timestamp))); } return timestamp; }
public boolean shouldRefetch() { // Time after which resource should be refetched. long refetchExpiration = isStrictNoCache() ? date + getRefetchStrictNoCacheAfterMs() : getCacheExpiration(); return refetchExpiration <= getTimeSource().currentTimeMillis(); }