001// *************************************************************************************************************************** 002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * 003// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * 004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * 005// * with the License. You may obtain a copy of the License at * 006// * * 007// * http://www.apache.org/licenses/LICENSE-2.0 * 008// * * 009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * 010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * 011// * specific language governing permissions and limitations under the License. * 012// *************************************************************************************************************************** 013package org.apache.juneau.http.header; 014 015import java.util.function.*; 016 017import org.apache.juneau.http.annotation.*; 018 019/** 020 * Represents a parsed <l>Cache-Control</l> HTTP request header. 021 * 022 * <p> 023 * Used to specify directives that must be obeyed by all caching mechanisms along the request-response chain. 024 * 025 * <h5 class='figure'>Example</h5> 026 * <p class='bcode w800'> 027 * Cache-Control: no-cache 028 * </p> 029 * 030 * <h5 class='topic'>RFC2616 Specification</h5> 031 * 032 * The Cache-Control general-header field is used to specify directives that MUST be obeyed by all caching mechanisms 033 * along the request/response chain. 034 * The directives specify behavior intended to prevent caches from adversely interfering with the request or response. 035 * These directives typically override the default caching algorithms. 036 * Cache directives are unidirectional in that the presence of a directive in a request does not imply that the same 037 * directive is to be given in the response. 038 * 039 * <p> 040 * Note that HTTP/1.0 caches might not implement Cache-Control and might only implement Pragma: no-cache (see section 041 * 14.32). 042 * 043 * <p> 044 * Cache directives MUST be passed through by a proxy or gateway application, regardless of their significance to that 045 * application, since the directives might be applicable to all recipients along the request/response chain. 046 * It is not possible to specify a cache- directive for a specific cache. 047 * 048 * <p class='bcode w800'> 049 * Cache-Control = "Cache-Control" ":" 1#cache-directive 050 * cache-directive = cache-request-directive 051 * | cache-response-directive 052 * cache-request-directive = 053 * "no-cache" ; Section 14.9.1 054 * | "no-store" ; Section 14.9.2 055 * | "max-age" "=" delta-seconds ; Section 14.9.3, 14.9.4 056 * | "max-stale" [ "=" delta-seconds ] ; Section 14.9.3 057 * | "min-fresh" "=" delta-seconds ; Section 14.9.3 058 * | "no-transform" ; Section 14.9.5 059 * | "only-if-cached" ; Section 14.9.4 060 * | cache-extension ; Section 14.9.6 061 * cache-response-directive = 062 * "public" ; Section 14.9.1 063 * | "private" [ "=" <"> 1#field-name <"> ] ; Section 14.9.1 064 * | "no-cache" [ "=" <"> 1#field-name <"> ]; Section 14.9.1 065 * | "no-store" ; Section 14.9.2 066 * | "no-transform" ; Section 14.9.5 067 * | "must-revalidate" ; Section 14.9.4 068 * | "proxy-revalidate" ; Section 14.9.4 069 * | "max-age" "=" delta-seconds ; Section 14.9.3 070 * | "s-maxage" "=" delta-seconds ; Section 14.9.3 071 * | cache-extension ; Section 14.9.6 072 * cache-extension = token [ "=" ( token | quoted-string ) ] 073 * </p> 074 * 075 * <p> 076 * When a directive appears without any 1#field-name parameter, the directive applies to the entire request or response. 077 * When such a directive appears with a 1#field-name parameter, it applies only to the named field or fields, and not 078 * to the rest of the request or response. This mechanism supports extensibility; implementations of future versions 079 * of the HTTP protocol might apply these directives to header fields not defined in HTTP/1.1. 080 * 081 * <p> 082 * The cache-control directives can be broken down into these general categories: 083 * <ul> 084 * <li>Restrictions on what are cacheable; these may only be imposed by the origin server. 085 * <li>Restrictions on what may be stored by a cache; these may be imposed by either the origin server or the user 086 * agent. 087 * <li>Modifications of the basic expiration mechanism; these may be imposed by either the origin server or the 088 * user agent. 089 * <li>Controls over cache revalidation and reload; these may only be imposed by a user agent. 090 * <li>Control over transformation of entities. 091 * <li>Extensions to the caching system. 092 * </ul> 093 * 094 * <ul class='seealso'> 095 * <li class='extlink'>{@doc ExtRFC2616} 096 * </ul> 097 */ 098@Header("Cache-Control") 099public class CacheControl extends BasicStringHeader { 100 101 private static final long serialVersionUID = 1L; 102 103 /** 104 * Convenience creator. 105 * 106 * @param value 107 * The header value. 108 * <br>Can be any of the following: 109 * <ul> 110 * <li>{@link String} 111 * <li>Anything else - Converted to <c>String</c> then parsed. 112 * </ul> 113 * @return A new {@link CacheControl} object. 114 */ 115 public static CacheControl of(Object value) { 116 if (value == null) 117 return null; 118 return new CacheControl(value); 119 } 120 121 /** 122 * Convenience creator using supplier. 123 * 124 * <p> 125 * Header value is re-evaluated on each call to {@link #getValue()}. 126 * 127 * @param value 128 * The header value supplier. 129 * <br>Can be any of the following: 130 * <ul> 131 * <li>{@link String} 132 * <li>Anything else - Converted to <c>String</c> then parsed. 133 * </ul> 134 * @return A new {@link CacheControl} object. 135 */ 136 public static CacheControl of(Supplier<?> value) { 137 if (value == null) 138 return null; 139 return new CacheControl(value); 140 } 141 142 /** 143 * Constructor. 144 * 145 * @param value 146 * The header value. 147 * <br>Can be any of the following: 148 * <ul> 149 * <li>{@link String} 150 * <li>Anything else - Converted to <c>String</c> then parsed. 151 * <li>A {@link Supplier} of anything on this list. 152 * </ul> 153 */ 154 public CacheControl(Object value) { 155 super("Cache-Control", value); 156 } 157 158 /** 159 * Constructor 160 * 161 * @param value 162 * The header value. 163 */ 164 public CacheControl(String value) { 165 this((Object)value); 166 } 167}