Skip to content

Commit 77e3f36

Browse files
1 parent 5d51de7 commit 77e3f36

4 files changed

Lines changed: 687 additions & 0 deletions

File tree

src/Compute/CachePolicy.php

Lines changed: 335 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,335 @@
1+
<?php
2+
/*
3+
* Copyright 2014 Google Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
6+
* use this file except in compliance with the License. You may obtain a copy of
7+
* the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14+
* License for the specific language governing permissions and limitations under
15+
* the License.
16+
*/
17+
18+
namespace Google\Service\Compute;
19+
20+
class CachePolicy extends \Google\Collection
21+
{
22+
/**
23+
* Automatically cache static content, including common image formats, media
24+
* (video and audio), and web assets (JavaScript and CSS). Requests and
25+
* responses that are marked as uncacheable, as well as dynamic content
26+
* (including HTML), will not be cached.
27+
*/
28+
public const CACHE_MODE_CACHE_ALL_STATIC = 'CACHE_ALL_STATIC';
29+
/**
30+
* Cache all content, ignoring any "private", "no-store" or "no-cache"
31+
* directives in Cache-Control response headers. Warning: this may result in
32+
* Cloud CDN caching private, per-user (user identifiable) content.
33+
*/
34+
public const CACHE_MODE_FORCE_CACHE_ALL = 'FORCE_CACHE_ALL';
35+
/**
36+
* Requires the origin to set valid caching headers to cache content.
37+
* Responses without these headers will not be cached at the edge, and will
38+
* require a full trip to the origin on every request, potentially impacting
39+
* performance and increasing load on the origin server.
40+
*/
41+
public const CACHE_MODE_USE_ORIGIN_HEADERS = 'USE_ORIGIN_HEADERS';
42+
protected $collection_key = 'negativeCachingPolicy';
43+
/**
44+
* Bypass the cache when the specified request headers are matched by name,
45+
* e.g. Pragma or Authorization headers. Values are case-insensitive. Up to 5
46+
* header names can be specified. The cache is bypassed for all `cacheMode`
47+
* values.
48+
*
49+
* @var string[]
50+
*/
51+
public $cacheBypassRequestHeaderNames;
52+
protected $cacheKeyPolicyType = CachePolicyCacheKeyPolicy::class;
53+
protected $cacheKeyPolicyDataType = '';
54+
/**
55+
* Specifies the cache setting for all responses from this route. If not
56+
* specified, Cloud CDN uses `CACHE_ALL_STATIC` mode.
57+
*
58+
* @var string
59+
*/
60+
public $cacheMode;
61+
protected $clientTtlType = Duration::class;
62+
protected $clientTtlDataType = '';
63+
protected $defaultTtlType = Duration::class;
64+
protected $defaultTtlDataType = '';
65+
protected $maxTtlType = Duration::class;
66+
protected $maxTtlDataType = '';
67+
/**
68+
* Negative caching allows per-status code TTLs to be set, in order to apply
69+
* fine-grained caching for common errors or redirects. This can reduce the
70+
* load on your origin and improve end-user experience by reducing response
71+
* latency. When the `cacheMode` is set to `CACHE_ALL_STATIC` or
72+
* `USE_ORIGIN_HEADERS`, negative caching applies to responses with the
73+
* specified response code that lack any Cache-Control, Expires, or Pragma:
74+
* no-cache directives. When the `cacheMode` is set to `FORCE_CACHE_ALL`,
75+
* negative caching applies to all responses with the specified response code,
76+
* and overrides any caching headers. By default, Cloud CDN applies the
77+
* following TTLs to these HTTP status codes:
78+
*
79+
* * 300 (Multiple Choice), 301, 308 (Permanent Redirects): 10m * 404 (Not
80+
* Found), 410 (Gone), 451 (Unavailable For Legal Reasons): 120s * 405 (Method
81+
* Not Found), 501 (Not Implemented): 60s
82+
*
83+
* These defaults can be overridden in `negativeCachingPolicy`. If not
84+
* specified, Cloud CDN applies negative caching by default.
85+
*
86+
* @var bool
87+
*/
88+
public $negativeCaching;
89+
protected $negativeCachingPolicyType = CachePolicyNegativeCachingPolicy::class;
90+
protected $negativeCachingPolicyDataType = 'array';
91+
/**
92+
* If true then Cloud CDN will combine multiple concurrent cache fill requests
93+
* into a small number of requests to the origin. If not specified, Cloud CDN
94+
* applies request coalescing by default.
95+
*
96+
* @var bool
97+
*/
98+
public $requestCoalescing;
99+
protected $serveWhileStaleType = Duration::class;
100+
protected $serveWhileStaleDataType = '';
101+
102+
/**
103+
* Bypass the cache when the specified request headers are matched by name,
104+
* e.g. Pragma or Authorization headers. Values are case-insensitive. Up to 5
105+
* header names can be specified. The cache is bypassed for all `cacheMode`
106+
* values.
107+
*
108+
* @param string[] $cacheBypassRequestHeaderNames
109+
*/
110+
public function setCacheBypassRequestHeaderNames($cacheBypassRequestHeaderNames)
111+
{
112+
$this->cacheBypassRequestHeaderNames = $cacheBypassRequestHeaderNames;
113+
}
114+
/**
115+
* @return string[]
116+
*/
117+
public function getCacheBypassRequestHeaderNames()
118+
{
119+
return $this->cacheBypassRequestHeaderNames;
120+
}
121+
/**
122+
* The cache key configuration. If not specified, the default behavior depends
123+
* on the backend type: for Backend Services, the complete request URI is
124+
* used; for Backend Buckets, the request URI is used without the protocol or
125+
* host, and only query parameters known to Cloud Storage are included.
126+
*
127+
* @param CachePolicyCacheKeyPolicy $cacheKeyPolicy
128+
*/
129+
public function setCacheKeyPolicy(CachePolicyCacheKeyPolicy $cacheKeyPolicy)
130+
{
131+
$this->cacheKeyPolicy = $cacheKeyPolicy;
132+
}
133+
/**
134+
* @return CachePolicyCacheKeyPolicy
135+
*/
136+
public function getCacheKeyPolicy()
137+
{
138+
return $this->cacheKeyPolicy;
139+
}
140+
/**
141+
* Specifies the cache setting for all responses from this route. If not
142+
* specified, Cloud CDN uses `CACHE_ALL_STATIC` mode.
143+
*
144+
* Accepted values: CACHE_ALL_STATIC, FORCE_CACHE_ALL, USE_ORIGIN_HEADERS
145+
*
146+
* @param self::CACHE_MODE_* $cacheMode
147+
*/
148+
public function setCacheMode($cacheMode)
149+
{
150+
$this->cacheMode = $cacheMode;
151+
}
152+
/**
153+
* @return self::CACHE_MODE_*
154+
*/
155+
public function getCacheMode()
156+
{
157+
return $this->cacheMode;
158+
}
159+
/**
160+
* Specifies a separate client (e.g. browser client) maximum TTL for cached
161+
* content. This is used to clamp the max-age (or Expires) value sent to the
162+
* client. With `FORCE_CACHE_ALL`, the lesser of `clientTtl` and `defaultTtl`
163+
* is used for the response max-age directive, along with a "public"
164+
* directive. For cacheable content in `CACHE_ALL_STATIC` mode, `clientTtl`
165+
* clamps the max-age from the origin (if specified), or else sets the
166+
* response max-age directive to the lesser of the `clientTtl` and
167+
* `defaultTtl`, and also ensures a "public" cache-control directive is
168+
* present. The maximum allowed value is 31,622,400s (1 year). If not
169+
* specified, Cloud CDN uses 3600s (1 hour) for `CACHE_ALL_STATIC` mode.
170+
* Cannot exceed `maxTtl`. Cannot be specified when `cacheMode` is
171+
* `USE_ORIGIN_HEADERS`.
172+
*
173+
* @param Duration $clientTtl
174+
*/
175+
public function setClientTtl(Duration $clientTtl)
176+
{
177+
$this->clientTtl = $clientTtl;
178+
}
179+
/**
180+
* @return Duration
181+
*/
182+
public function getClientTtl()
183+
{
184+
return $this->clientTtl;
185+
}
186+
/**
187+
* Specifies the default TTL for cached content for responses that do not have
188+
* an existing valid TTL (max-age or s-maxage). Setting a TTL of "0" means
189+
* "always revalidate". The value of `defaultTtl` cannot be set to a value
190+
* greater than that of `maxTtl`. When the `cacheMode` is set to
191+
* `FORCE_CACHE_ALL`, the `defaultTtl` will overwrite the TTL set in all
192+
* responses. The maximum allowed value is 31,622,400s (1 year). Infrequently
193+
* accessed objects may be evicted from the cache before the defined TTL. If
194+
* not specified, Cloud CDN uses 3600s (1 hour) for `CACHE_ALL_STATIC` and
195+
* `FORCE_CACHE_ALL` modes. Cannot be specified when `cacheMode` is
196+
* `USE_ORIGIN_HEADERS`.
197+
*
198+
* @param Duration $defaultTtl
199+
*/
200+
public function setDefaultTtl(Duration $defaultTtl)
201+
{
202+
$this->defaultTtl = $defaultTtl;
203+
}
204+
/**
205+
* @return Duration
206+
*/
207+
public function getDefaultTtl()
208+
{
209+
return $this->defaultTtl;
210+
}
211+
/**
212+
* Specifies the maximum allowed TTL for cached content. Cache directives that
213+
* attempt to set a max-age or s-maxage higher than this, or an Expires header
214+
* more than `maxTtl` seconds in the future will be capped at the value of
215+
* `maxTtl`, as if it were the value of an s-maxage Cache-Control directive.
216+
* Headers sent to the client will not be modified. Setting a TTL of "0" means
217+
* "always revalidate". The maximum allowed value is 31,622,400s (1 year).
218+
* Infrequently accessed objects may be evicted from the cache before the
219+
* defined TTL. If not specified, Cloud CDN uses 86400s (1 day) for
220+
* `CACHE_ALL_STATIC` mode. Can be specified only for `CACHE_ALL_STATIC` cache
221+
* mode.
222+
*
223+
* @param Duration $maxTtl
224+
*/
225+
public function setMaxTtl(Duration $maxTtl)
226+
{
227+
$this->maxTtl = $maxTtl;
228+
}
229+
/**
230+
* @return Duration
231+
*/
232+
public function getMaxTtl()
233+
{
234+
return $this->maxTtl;
235+
}
236+
/**
237+
* Negative caching allows per-status code TTLs to be set, in order to apply
238+
* fine-grained caching for common errors or redirects. This can reduce the
239+
* load on your origin and improve end-user experience by reducing response
240+
* latency. When the `cacheMode` is set to `CACHE_ALL_STATIC` or
241+
* `USE_ORIGIN_HEADERS`, negative caching applies to responses with the
242+
* specified response code that lack any Cache-Control, Expires, or Pragma:
243+
* no-cache directives. When the `cacheMode` is set to `FORCE_CACHE_ALL`,
244+
* negative caching applies to all responses with the specified response code,
245+
* and overrides any caching headers. By default, Cloud CDN applies the
246+
* following TTLs to these HTTP status codes:
247+
*
248+
* * 300 (Multiple Choice), 301, 308 (Permanent Redirects): 10m * 404 (Not
249+
* Found), 410 (Gone), 451 (Unavailable For Legal Reasons): 120s * 405 (Method
250+
* Not Found), 501 (Not Implemented): 60s
251+
*
252+
* These defaults can be overridden in `negativeCachingPolicy`. If not
253+
* specified, Cloud CDN applies negative caching by default.
254+
*
255+
* @param bool $negativeCaching
256+
*/
257+
public function setNegativeCaching($negativeCaching)
258+
{
259+
$this->negativeCaching = $negativeCaching;
260+
}
261+
/**
262+
* @return bool
263+
*/
264+
public function getNegativeCaching()
265+
{
266+
return $this->negativeCaching;
267+
}
268+
/**
269+
* Sets a cache TTL for the specified HTTP status code. `negativeCaching` must
270+
* be enabled to configure `negativeCachingPolicy`. Omitting the policy and
271+
* leaving `negativeCaching` enabled will use Cloud CDN's default cache TTLs.
272+
* Note that when specifying an explicit `negativeCachingPolicy`, you should
273+
* take care to specify a cache TTL for all response codes that you wish to
274+
* cache. Cloud CDN will not apply any default negative caching when a policy
275+
* exists.
276+
*
277+
* @param CachePolicyNegativeCachingPolicy[] $negativeCachingPolicy
278+
*/
279+
public function setNegativeCachingPolicy($negativeCachingPolicy)
280+
{
281+
$this->negativeCachingPolicy = $negativeCachingPolicy;
282+
}
283+
/**
284+
* @return CachePolicyNegativeCachingPolicy[]
285+
*/
286+
public function getNegativeCachingPolicy()
287+
{
288+
return $this->negativeCachingPolicy;
289+
}
290+
/**
291+
* If true then Cloud CDN will combine multiple concurrent cache fill requests
292+
* into a small number of requests to the origin. If not specified, Cloud CDN
293+
* applies request coalescing by default.
294+
*
295+
* @param bool $requestCoalescing
296+
*/
297+
public function setRequestCoalescing($requestCoalescing)
298+
{
299+
$this->requestCoalescing = $requestCoalescing;
300+
}
301+
/**
302+
* @return bool
303+
*/
304+
public function getRequestCoalescing()
305+
{
306+
return $this->requestCoalescing;
307+
}
308+
/**
309+
* Serve existing content from the cache (if available) when revalidating
310+
* content with the origin, or when an error is encountered when refreshing
311+
* the cache. This setting defines the default "max-stale" duration for any
312+
* cached responses that do not specify a max-stale directive. Stale responses
313+
* that exceed the TTL configured here will not be served. The default limit
314+
* (max-stale) is 86400s (1 day), which will allow stale content to be served
315+
* up to this limit beyond the max-age (or s-maxage) of a cached response. The
316+
* maximum allowed value is 604800 (1 week). Set this to zero (0) to disable
317+
* serve-while-stale.
318+
*
319+
* @param Duration $serveWhileStale
320+
*/
321+
public function setServeWhileStale(Duration $serveWhileStale)
322+
{
323+
$this->serveWhileStale = $serveWhileStale;
324+
}
325+
/**
326+
* @return Duration
327+
*/
328+
public function getServeWhileStale()
329+
{
330+
return $this->serveWhileStale;
331+
}
332+
}
333+
334+
// Adding a class alias for backwards compatibility with the previous class name.
335+
class_alias(CachePolicy::class, 'Google_Service_Compute_CachePolicy');

0 commit comments

Comments
 (0)