BackendServiceCdnPolicy.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  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. namespace Google\Service\Compute;
  18. class BackendServiceCdnPolicy extends \Google\Collection
  19. {
  20. /**
  21. * Automatically cache static content, including common image formats, media
  22. * (video and audio), and web assets (JavaScript and CSS). Requests and
  23. * responses that are marked as uncacheable, as well as dynamic content
  24. * (including HTML), will not be cached.
  25. */
  26. public const CACHE_MODE_CACHE_ALL_STATIC = 'CACHE_ALL_STATIC';
  27. /**
  28. * Cache all content, ignoring any "private", "no-store" or "no-cache"
  29. * directives in Cache-Control response headers. Warning: this may result in
  30. * Cloud CDN caching private, per-user (user identifiable) content.
  31. */
  32. public const CACHE_MODE_FORCE_CACHE_ALL = 'FORCE_CACHE_ALL';
  33. public const CACHE_MODE_INVALID_CACHE_MODE = 'INVALID_CACHE_MODE';
  34. /**
  35. * Requires the origin to set valid caching headers to cache content.
  36. * Responses without these headers will not be cached at Google's edge, and
  37. * will require a full trip to the origin on every request, potentially
  38. * impacting performance and increasing load on the origin server.
  39. */
  40. public const CACHE_MODE_USE_ORIGIN_HEADERS = 'USE_ORIGIN_HEADERS';
  41. protected $collection_key = 'signedUrlKeyNames';
  42. protected $bypassCacheOnRequestHeadersType = BackendServiceCdnPolicyBypassCacheOnRequestHeader::class;
  43. protected $bypassCacheOnRequestHeadersDataType = 'array';
  44. protected $cacheKeyPolicyType = CacheKeyPolicy::class;
  45. protected $cacheKeyPolicyDataType = '';
  46. /**
  47. * Specifies the cache setting for all responses from this backend. The
  48. * possible values are:USE_ORIGIN_HEADERS Requires the origin to set valid
  49. * caching headers to cache content. Responses without these headers will not
  50. * be cached at Google's edge, and will require a full trip to the origin on
  51. * every request, potentially impacting performance and increasing load on the
  52. * origin server.FORCE_CACHE_ALL Cache all content, ignoring any "private",
  53. * "no-store" or "no-cache" directives in Cache-Control response headers.
  54. * Warning: this may result in Cloud CDN caching private, per-user (user
  55. * identifiable) content.CACHE_ALL_STATIC Automatically cache static content,
  56. * including common image formats, media (video and audio), and web assets
  57. * (JavaScript and CSS). Requests and responses that are marked as
  58. * uncacheable, as well as dynamic content (including HTML), will not be
  59. * cached.
  60. *
  61. * If no value is provided for cdnPolicy.cacheMode, it defaults to
  62. * CACHE_ALL_STATIC.
  63. *
  64. * @var string
  65. */
  66. public $cacheMode;
  67. /**
  68. * Specifies a separate client (e.g. browser client) maximum TTL. This is used
  69. * to clamp the max-age (or Expires) value sent to the client. With
  70. * FORCE_CACHE_ALL, the lesser of client_ttl and default_ttl is used for the
  71. * response max-age directive, along with a "public" directive. For cacheable
  72. * content in CACHE_ALL_STATIC mode, client_ttl clamps the max-age from the
  73. * origin (if specified), or else sets the response max-age directive to the
  74. * lesser of the client_ttl and default_ttl, and also ensures a "public"
  75. * cache-control directive is present. If a client TTL is not specified, a
  76. * default value (1 hour) will be used. The maximum allowed value is
  77. * 31,622,400s (1 year).
  78. *
  79. * @var int
  80. */
  81. public $clientTtl;
  82. /**
  83. * Specifies the default TTL for cached content served by this origin for
  84. * responses that do not have an existing valid TTL (max-age or s-maxage).
  85. * Setting a TTL of "0" means "always revalidate". The value of defaultTTL
  86. * cannot be set to a value greater than that of maxTTL, but can be equal.
  87. * When the cacheMode is set to FORCE_CACHE_ALL, the defaultTTL will overwrite
  88. * the TTL set in all responses. The maximum allowed value is 31,622,400s (1
  89. * year), noting that infrequently accessed objects may be evicted from the
  90. * cache before the defined TTL.
  91. *
  92. * @var int
  93. */
  94. public $defaultTtl;
  95. /**
  96. * Specifies the maximum allowed TTL for cached content served by this origin.
  97. * Cache directives that attempt to set a max-age or s-maxage higher than
  98. * this, or an Expires header more than maxTTL seconds in the future will be
  99. * capped at the value of maxTTL, as if it were the value of an s-maxage
  100. * Cache-Control directive. Headers sent to the client will not be modified.
  101. * Setting a TTL of "0" means "always revalidate". The maximum allowed value
  102. * is 31,622,400s (1 year), noting that infrequently accessed objects may be
  103. * evicted from the cache before the defined TTL.
  104. *
  105. * @var int
  106. */
  107. public $maxTtl;
  108. /**
  109. * Negative caching allows per-status code TTLs to be set, in order to apply
  110. * fine-grained caching for common errors or redirects. This can reduce the
  111. * load on your origin and improve end-user experience by reducing response
  112. * latency. When the cache mode is set to CACHE_ALL_STATIC or
  113. * USE_ORIGIN_HEADERS, negative caching applies to responses with the
  114. * specified response code that lack any Cache-Control, Expires, or Pragma:
  115. * no-cache directives. When the cache mode is set to FORCE_CACHE_ALL,
  116. * negative caching applies to all responses with the specified response code,
  117. * and override any caching headers. By default, Cloud CDN will apply the
  118. * following default TTLs to these status codes: HTTP 300 (Multiple Choice),
  119. * 301, 308 (Permanent Redirects): 10m HTTP 404 (Not Found), 410 (Gone), 451
  120. * (Unavailable For Legal Reasons): 120s HTTP 405 (Method Not Found), 501 (Not
  121. * Implemented): 60s. These defaults can be overridden in
  122. * negative_caching_policy.
  123. *
  124. * @var bool
  125. */
  126. public $negativeCaching;
  127. protected $negativeCachingPolicyType = BackendServiceCdnPolicyNegativeCachingPolicy::class;
  128. protected $negativeCachingPolicyDataType = 'array';
  129. /**
  130. * If true then Cloud CDN will combine multiple concurrent cache fill requests
  131. * into a small number of requests to the origin.
  132. *
  133. * @var bool
  134. */
  135. public $requestCoalescing;
  136. /**
  137. * Serve existing content from the cache (if available) when revalidating
  138. * content with the origin, or when an error is encountered when refreshing
  139. * the cache. This setting defines the default "max-stale" duration for any
  140. * cached responses that do not specify a max-stale directive. Stale responses
  141. * that exceed the TTL configured here will not be served. The default limit
  142. * (max-stale) is 86400s (1 day), which will allow stale content to be served
  143. * up to this limit beyond the max-age (or s-maxage) of a cached response. The
  144. * maximum allowed value is 604800 (1 week). Set this to zero (0) to disable
  145. * serve-while-stale.
  146. *
  147. * @var int
  148. */
  149. public $serveWhileStale;
  150. /**
  151. * Maximum number of seconds the response to a signed URL request will be
  152. * considered fresh. After this time period, the response will be revalidated
  153. * before being served. Defaults to 1hr (3600s). When serving responses to
  154. * signed URL requests, Cloud CDN will internally behave as though all
  155. * responses from this backend had a "Cache-Control: public, max-age=[TTL]"
  156. * header, regardless of any existing Cache-Control header. The actual headers
  157. * served in responses will not be altered.
  158. *
  159. * @var string
  160. */
  161. public $signedUrlCacheMaxAgeSec;
  162. /**
  163. * [Output Only] Names of the keys for signing request URLs.
  164. *
  165. * @var string[]
  166. */
  167. public $signedUrlKeyNames;
  168. /**
  169. * Bypass the cache when the specified request headers are matched - e.g.
  170. * Pragma or Authorization headers. Up to 5 headers can be specified. The
  171. * cache is bypassed for all cdnPolicy.cacheMode settings.
  172. *
  173. * @param BackendServiceCdnPolicyBypassCacheOnRequestHeader[] $bypassCacheOnRequestHeaders
  174. */
  175. public function setBypassCacheOnRequestHeaders($bypassCacheOnRequestHeaders)
  176. {
  177. $this->bypassCacheOnRequestHeaders = $bypassCacheOnRequestHeaders;
  178. }
  179. /**
  180. * @return BackendServiceCdnPolicyBypassCacheOnRequestHeader[]
  181. */
  182. public function getBypassCacheOnRequestHeaders()
  183. {
  184. return $this->bypassCacheOnRequestHeaders;
  185. }
  186. /**
  187. * The CacheKeyPolicy for this CdnPolicy.
  188. *
  189. * @param CacheKeyPolicy $cacheKeyPolicy
  190. */
  191. public function setCacheKeyPolicy(CacheKeyPolicy $cacheKeyPolicy)
  192. {
  193. $this->cacheKeyPolicy = $cacheKeyPolicy;
  194. }
  195. /**
  196. * @return CacheKeyPolicy
  197. */
  198. public function getCacheKeyPolicy()
  199. {
  200. return $this->cacheKeyPolicy;
  201. }
  202. /**
  203. * Specifies the cache setting for all responses from this backend. The
  204. * possible values are:USE_ORIGIN_HEADERS Requires the origin to set valid
  205. * caching headers to cache content. Responses without these headers will not
  206. * be cached at Google's edge, and will require a full trip to the origin on
  207. * every request, potentially impacting performance and increasing load on the
  208. * origin server.FORCE_CACHE_ALL Cache all content, ignoring any "private",
  209. * "no-store" or "no-cache" directives in Cache-Control response headers.
  210. * Warning: this may result in Cloud CDN caching private, per-user (user
  211. * identifiable) content.CACHE_ALL_STATIC Automatically cache static content,
  212. * including common image formats, media (video and audio), and web assets
  213. * (JavaScript and CSS). Requests and responses that are marked as
  214. * uncacheable, as well as dynamic content (including HTML), will not be
  215. * cached.
  216. *
  217. * If no value is provided for cdnPolicy.cacheMode, it defaults to
  218. * CACHE_ALL_STATIC.
  219. *
  220. * Accepted values: CACHE_ALL_STATIC, FORCE_CACHE_ALL, INVALID_CACHE_MODE,
  221. * USE_ORIGIN_HEADERS
  222. *
  223. * @param self::CACHE_MODE_* $cacheMode
  224. */
  225. public function setCacheMode($cacheMode)
  226. {
  227. $this->cacheMode = $cacheMode;
  228. }
  229. /**
  230. * @return self::CACHE_MODE_*
  231. */
  232. public function getCacheMode()
  233. {
  234. return $this->cacheMode;
  235. }
  236. /**
  237. * Specifies a separate client (e.g. browser client) maximum TTL. This is used
  238. * to clamp the max-age (or Expires) value sent to the client. With
  239. * FORCE_CACHE_ALL, the lesser of client_ttl and default_ttl is used for the
  240. * response max-age directive, along with a "public" directive. For cacheable
  241. * content in CACHE_ALL_STATIC mode, client_ttl clamps the max-age from the
  242. * origin (if specified), or else sets the response max-age directive to the
  243. * lesser of the client_ttl and default_ttl, and also ensures a "public"
  244. * cache-control directive is present. If a client TTL is not specified, a
  245. * default value (1 hour) will be used. The maximum allowed value is
  246. * 31,622,400s (1 year).
  247. *
  248. * @param int $clientTtl
  249. */
  250. public function setClientTtl($clientTtl)
  251. {
  252. $this->clientTtl = $clientTtl;
  253. }
  254. /**
  255. * @return int
  256. */
  257. public function getClientTtl()
  258. {
  259. return $this->clientTtl;
  260. }
  261. /**
  262. * Specifies the default TTL for cached content served by this origin for
  263. * responses that do not have an existing valid TTL (max-age or s-maxage).
  264. * Setting a TTL of "0" means "always revalidate". The value of defaultTTL
  265. * cannot be set to a value greater than that of maxTTL, but can be equal.
  266. * When the cacheMode is set to FORCE_CACHE_ALL, the defaultTTL will overwrite
  267. * the TTL set in all responses. The maximum allowed value is 31,622,400s (1
  268. * year), noting that infrequently accessed objects may be evicted from the
  269. * cache before the defined TTL.
  270. *
  271. * @param int $defaultTtl
  272. */
  273. public function setDefaultTtl($defaultTtl)
  274. {
  275. $this->defaultTtl = $defaultTtl;
  276. }
  277. /**
  278. * @return int
  279. */
  280. public function getDefaultTtl()
  281. {
  282. return $this->defaultTtl;
  283. }
  284. /**
  285. * Specifies the maximum allowed TTL for cached content served by this origin.
  286. * Cache directives that attempt to set a max-age or s-maxage higher than
  287. * this, or an Expires header more than maxTTL seconds in the future will be
  288. * capped at the value of maxTTL, as if it were the value of an s-maxage
  289. * Cache-Control directive. Headers sent to the client will not be modified.
  290. * Setting a TTL of "0" means "always revalidate". The maximum allowed value
  291. * is 31,622,400s (1 year), noting that infrequently accessed objects may be
  292. * evicted from the cache before the defined TTL.
  293. *
  294. * @param int $maxTtl
  295. */
  296. public function setMaxTtl($maxTtl)
  297. {
  298. $this->maxTtl = $maxTtl;
  299. }
  300. /**
  301. * @return int
  302. */
  303. public function getMaxTtl()
  304. {
  305. return $this->maxTtl;
  306. }
  307. /**
  308. * Negative caching allows per-status code TTLs to be set, in order to apply
  309. * fine-grained caching for common errors or redirects. This can reduce the
  310. * load on your origin and improve end-user experience by reducing response
  311. * latency. When the cache mode is set to CACHE_ALL_STATIC or
  312. * USE_ORIGIN_HEADERS, negative caching applies to responses with the
  313. * specified response code that lack any Cache-Control, Expires, or Pragma:
  314. * no-cache directives. When the cache mode is set to FORCE_CACHE_ALL,
  315. * negative caching applies to all responses with the specified response code,
  316. * and override any caching headers. By default, Cloud CDN will apply the
  317. * following default TTLs to these status codes: HTTP 300 (Multiple Choice),
  318. * 301, 308 (Permanent Redirects): 10m HTTP 404 (Not Found), 410 (Gone), 451
  319. * (Unavailable For Legal Reasons): 120s HTTP 405 (Method Not Found), 501 (Not
  320. * Implemented): 60s. These defaults can be overridden in
  321. * negative_caching_policy.
  322. *
  323. * @param bool $negativeCaching
  324. */
  325. public function setNegativeCaching($negativeCaching)
  326. {
  327. $this->negativeCaching = $negativeCaching;
  328. }
  329. /**
  330. * @return bool
  331. */
  332. public function getNegativeCaching()
  333. {
  334. return $this->negativeCaching;
  335. }
  336. /**
  337. * Sets a cache TTL for the specified HTTP status code. negative_caching must
  338. * be enabled to configure negative_caching_policy. Omitting the policy and
  339. * leaving negative_caching enabled will use Cloud CDN's default cache TTLs.
  340. * Note that when specifying an explicit negative_caching_policy, you should
  341. * take care to specify a cache TTL for all response codes that you wish to
  342. * cache. Cloud CDN will not apply any default negative caching when a policy
  343. * exists.
  344. *
  345. * @param BackendServiceCdnPolicyNegativeCachingPolicy[] $negativeCachingPolicy
  346. */
  347. public function setNegativeCachingPolicy($negativeCachingPolicy)
  348. {
  349. $this->negativeCachingPolicy = $negativeCachingPolicy;
  350. }
  351. /**
  352. * @return BackendServiceCdnPolicyNegativeCachingPolicy[]
  353. */
  354. public function getNegativeCachingPolicy()
  355. {
  356. return $this->negativeCachingPolicy;
  357. }
  358. /**
  359. * If true then Cloud CDN will combine multiple concurrent cache fill requests
  360. * into a small number of requests to the origin.
  361. *
  362. * @param bool $requestCoalescing
  363. */
  364. public function setRequestCoalescing($requestCoalescing)
  365. {
  366. $this->requestCoalescing = $requestCoalescing;
  367. }
  368. /**
  369. * @return bool
  370. */
  371. public function getRequestCoalescing()
  372. {
  373. return $this->requestCoalescing;
  374. }
  375. /**
  376. * Serve existing content from the cache (if available) when revalidating
  377. * content with the origin, or when an error is encountered when refreshing
  378. * the cache. This setting defines the default "max-stale" duration for any
  379. * cached responses that do not specify a max-stale directive. Stale responses
  380. * that exceed the TTL configured here will not be served. The default limit
  381. * (max-stale) is 86400s (1 day), which will allow stale content to be served
  382. * up to this limit beyond the max-age (or s-maxage) of a cached response. The
  383. * maximum allowed value is 604800 (1 week). Set this to zero (0) to disable
  384. * serve-while-stale.
  385. *
  386. * @param int $serveWhileStale
  387. */
  388. public function setServeWhileStale($serveWhileStale)
  389. {
  390. $this->serveWhileStale = $serveWhileStale;
  391. }
  392. /**
  393. * @return int
  394. */
  395. public function getServeWhileStale()
  396. {
  397. return $this->serveWhileStale;
  398. }
  399. /**
  400. * Maximum number of seconds the response to a signed URL request will be
  401. * considered fresh. After this time period, the response will be revalidated
  402. * before being served. Defaults to 1hr (3600s). When serving responses to
  403. * signed URL requests, Cloud CDN will internally behave as though all
  404. * responses from this backend had a "Cache-Control: public, max-age=[TTL]"
  405. * header, regardless of any existing Cache-Control header. The actual headers
  406. * served in responses will not be altered.
  407. *
  408. * @param string $signedUrlCacheMaxAgeSec
  409. */
  410. public function setSignedUrlCacheMaxAgeSec($signedUrlCacheMaxAgeSec)
  411. {
  412. $this->signedUrlCacheMaxAgeSec = $signedUrlCacheMaxAgeSec;
  413. }
  414. /**
  415. * @return string
  416. */
  417. public function getSignedUrlCacheMaxAgeSec()
  418. {
  419. return $this->signedUrlCacheMaxAgeSec;
  420. }
  421. /**
  422. * [Output Only] Names of the keys for signing request URLs.
  423. *
  424. * @param string[] $signedUrlKeyNames
  425. */
  426. public function setSignedUrlKeyNames($signedUrlKeyNames)
  427. {
  428. $this->signedUrlKeyNames = $signedUrlKeyNames;
  429. }
  430. /**
  431. * @return string[]
  432. */
  433. public function getSignedUrlKeyNames()
  434. {
  435. return $this->signedUrlKeyNames;
  436. }
  437. }
  438. // Adding a class alias for backwards compatibility with the previous class name.
  439. class_alias(BackendServiceCdnPolicy::class, 'Google_Service_Compute_BackendServiceCdnPolicy');