设置客户端缓存过期时间的 Header。

@param response
响应
@param expiresSeconds
过期时间
342312
public static void setExpiresHeader(final HttpServletResponse response, final long expiresSeconds) {
		// Http 1.0 header, set a fix expires date.
		response.setDateHeader(HttpHeaders.EXPIRES, System.currentTimeMillis() + expiresSeconds * 1000);
		// Http 1.1 header, set a time after now.
		response.setHeader(HttpHeaders.CACHE_CONTROL, "private, max-age=" + expiresSeconds);
	}
1227871
public function setExpires(string $expires)
    {
        if (empty($expires)) {
            Throw new HeaderException('Empty expires is not allowed.');
        }

        $this->expires = $expires;
    }
1193354
protected void doResponseHeaders(final HttpServletResponse response, final String mimeType) {
        if (mimeType != null) {
            response.setContentType(mimeType);
        }
    }
1371870
def __cache_response(self, cache_key, res, method):
        
        if ('expires' in res.headers
                and method not in self.__uncached_methods__):
            cache_timeout = get_cache_time_left(res.headers.get('expires'))

            # Occasionally CCP swagger will return an outdated expire
            # warn and skip cache if timeout is <0
            if cache_timeout >= 0:
                self.cache.set(
                    cache_key,
                    CachedResponse(
                        status_code=res.status_code,
                        headers=res.headers,
                        content=res.content,
                        url=res.url,
                    ),
                )
            else:
                LOGGER.warning(
                    "[%s] returned expired result: %s", res.url,
                    res.headers)
                warnings.warn("[%s] returned expired result" % res.url)
552893
public ReadDocumentResponse readDocument(String documentId, long expireInSeconds) {
        ReadDocumentRequest request = new ReadDocumentRequest();
        request.setDocumentId(documentId);
        request.setExpireInSeconds(expireInSeconds);
        return this.readDocument(request);
    }
249457
protected void addNoCacheHeaders(HttpServletResponse response) {
		String cacheControlValue = response.getHeader(WebConstants.HEADER_CACHE_CONTROL);

		if (cacheControlValue != null && !cacheControlValue.isEmpty()) {
			cacheControlValue = cacheControlValue + ", " + WebConstants.CACHE_CONTROL_NO_STORE;
		} else {
			cacheControlValue = WebConstants.CACHE_CONTROL_NO_STORE;
		}

		response.setHeader(WebConstants.HEADER_CACHE_CONTROL, cacheControlValue);
		response.setHeader(WebConstants.HEADER_PRAGMA, WebConstants.PRAGMA_NO_CACHE);
	}
237198
private static long parseCacheHeader(Map<String, String> headers) {
    if (headers.get("CACHE-CONTROL") != null) {
      String cacheControlHeader = headers.get("CACHE-CONTROL");
      Matcher m = CACHE_CONTROL_PATTERN.matcher(cacheControlHeader);
      if (m.matches()) {
        return new Date().getTime() + Long.parseLong(m.group(1)) * 1000L;
      }
    }
    if (headers.get("EXPIRES") != null) {
      try {
        return DATE_HEADER_FORMAT.parse(headers.get("EXPIRES")).getTime();
      } catch (ParseException e) {
      }
    }
    // No result, no expiry strategy
    return 0;
  }
608112
protected boolean shouldResponseBeRecordedAsFailure(final HttpServletResponse response) {
        val status = response.getStatus();
        return status != HttpStatus.SC_CREATED && status != HttpStatus.SC_OK && status != HttpStatus.SC_MOVED_TEMPORARILY;
    }
1035967
public static void setFileDownloadHeader(final HttpServletResponse response, final String filename) {
		// 中文文件名支持
		String encodedFilename = Encodes.urlEncode(filename);
		response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + encodedFilename + '\"');
	}
447401
@Nonnull
  public final UnifiedResponse enableCaching (@Nonnegative final int nSeconds)
  {
    ValueEnforcer.isGT0 (nSeconds, "Seconds");

    // Remove any eventually set headers
    // Note: don't remove Last-Modified and ETag!
    removeExpires ();
    removeCacheControl ();
    m_aResponseHeaderMap.removeHeaders (CHttpHeader.PRAGMA);

    if (m_eHttpVersion.is10 ())
    {
      m_aResponseHeaderMap.setDateHeader (CHttpHeader.EXPIRES,
                                          PDTFactory.getCurrentLocalDateTime ().plusSeconds (nSeconds));
    }
    else
    {
      final CacheControlBuilder aCacheControlBuilder = new CacheControlBuilder ().setPublic (true)
                                                                                 .setMaxAgeSeconds (nSeconds);
      setCacheControl (aCacheControlBuilder);
    }
    return this;
  }
1272580
def has_uncacheable_headers(self, response):
        

        cc_dict = get_header_dict(response, 'Cache-Control')
        if cc_dict:
            if 'max-age' in cc_dict and cc_dict['max-age'] == '0':
                return True
            if 'no-cache' in cc_dict:
                return True
            if 'private' in cc_dict:
                return True
        if response.has_header('Expires'):
            if parse_http_date(response['Expires']) < time.time():
                return True
        return False
302899
protected void preventCaching(final HttpServletResponse response) {
        response.setHeader("Pragma", NO_CACHE);
        response.setDateHeader("Expires", 1L);
        response.setHeader(CACHE_CONTROL, NO_CACHE);
        response.addHeader(CACHE_CONTROL, "no-store");
    }
792011
function(){
    if (!service.token) {
      return;
    }
    if(typeof(service.token.expires_in) !== 'undefined' && service.token.expires_in !== null) {
      var expires_at = new Date();
      expires_at.setSeconds(expires_at.getSeconds() + parseInt(service.token.expires_in)-60); // 60 seconds less to secure browser and response latency
      service.token.expires_at = expires_at;
    }
    else {
      service.token.expires_at = null;
    }
  }
1257861
public static void setCookieValue(HttpServletResponse response, String cookieName,
            String cookieValue, int expireInHour) {
        Cookie cookie = new Cookie(cookieName, cookieValue);
        if (expireInHour > 0) {
            cookie.setMaxAge(60 * 60 * 24 * expireInHour);
        } else {
            cookie.setMaxAge(60 * 60 * 24);
        }
        response.addCookie(cookie);
    }
1092748
private void timeoutHasExpired(final Timeout timeout, final TimeoutExpirationContext context) {
        try {
            addMessage(timeout, context.getOriginalHeaders());
        } catch (Exception ex) {
            LOG.error("Error handling timeout {}", timeout, ex);
        }
    }
153328
@Override
    public CompletableFuture<Void> setExpireSecondsAsync(String key, int expireSeconds) {
        return (CompletableFuture) send("EXPIRE", null, (Type) null, key, key.getBytes(UTF8), String.valueOf(expireSeconds).getBytes(UTF8));
    }
746042
private function _setResponseHeaders()
    {
        $this->_response->setHeader("Expires", "Mon, 26 Jul 1997 05:00:00 GMT", true)
                        ->setHeader("Last-Modified", gmdate("D, d M Y H:i:s") . " GMT", true)
                        ->setHeader("Cache-Control", "no-store, no-cache, must-revalidate", true)
                        ->setHeader("Cache-Control", "post-check=0, pre-check=0", false)
                        ->setHeader("Pragma", "no-cache", true)
                        ->sendHeaders();
    }