Cache.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\HttpKernel\Attribute;
  11. /**
  12. * Describes the default HTTP cache headers on controllers.
  13. * Headers defined in the Cache attribute are ignored if they are already set
  14. * by the controller.
  15. *
  16. * @see https://symfony.com/doc/current/http_cache.html#making-your-responses-http-cacheable
  17. *
  18. * @author Fabien Potencier <fabien@symfony.com>
  19. */
  20. #[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD | \Attribute::TARGET_FUNCTION)]
  21. final class Cache
  22. {
  23. public function __construct(
  24. /**
  25. * The expiration date as a valid date for the strtotime() function.
  26. */
  27. public ?string $expires = null,
  28. /**
  29. * The number of seconds that the response is considered fresh by a private
  30. * cache like a web browser.
  31. */
  32. public int|string|null $maxage = null,
  33. /**
  34. * The number of seconds that the response is considered fresh by a public
  35. * cache like a reverse proxy cache.
  36. */
  37. public int|string|null $smaxage = null,
  38. /**
  39. * If true, the contents will be stored in a public cache and served to all
  40. * the next requests.
  41. */
  42. public ?bool $public = null,
  43. /**
  44. * If true, the response is not served stale by a cache in any circumstance
  45. * without first revalidating with the origin.
  46. */
  47. public bool $mustRevalidate = false,
  48. /**
  49. * Set "Vary" header.
  50. *
  51. * Example:
  52. * ['Accept-Encoding', 'User-Agent']
  53. *
  54. * @see https://symfony.com/doc/current/http_cache/cache_vary.html
  55. *
  56. * @var string[]
  57. */
  58. public array $vary = [],
  59. /**
  60. * An expression to compute the Last-Modified HTTP header.
  61. *
  62. * The expression is evaluated by the ExpressionLanguage component, it
  63. * receives all the request attributes and the resolved controller arguments.
  64. *
  65. * The result of the expression must be a DateTimeInterface.
  66. */
  67. public ?string $lastModified = null,
  68. /**
  69. * An expression to compute the ETag HTTP header.
  70. *
  71. * The expression is evaluated by the ExpressionLanguage component, it
  72. * receives all the request attributes and the resolved controller arguments.
  73. *
  74. * The result must be a string that will be hashed.
  75. */
  76. public ?string $etag = null,
  77. /**
  78. * max-stale Cache-Control header
  79. * It can be expressed in seconds or with a relative time format (1 day, 2 weeks, ...).
  80. */
  81. public int|string|null $maxStale = null,
  82. /**
  83. * stale-while-revalidate Cache-Control header
  84. * It can be expressed in seconds or with a relative time format (1 day, 2 weeks, ...).
  85. */
  86. public int|string|null $staleWhileRevalidate = null,
  87. /**
  88. * stale-if-error Cache-Control header
  89. * It can be expressed in seconds or with a relative time format (1 day, 2 weeks, ...).
  90. */
  91. public int|string|null $staleIfError = null,
  92. ) {
  93. }
  94. }