src/JanusHercules/RecurrentJobsCheapSearch/Domain/Entity/AnonymousSearchResultsCache.php line 17

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace JanusHercules\RecurrentJobsCheapSearch\Domain\Entity;
  4. use DateTime;
  5. use Doctrine\ORM\Mapping as ORM;
  6. /**
  7. * Caches full HTML responses for anonymous search results during cheap search mode.
  8. * This enables response caching across all app servers in the cluster.
  9. */
  10. #[ORM\Entity]
  11. #[ORM\Table(name: 'cheap_search_anonymous_results_cache')]
  12. #[ORM\Index(name: 'csarc_expires_at_idx', columns: ['expires_at'])]
  13. class AnonymousSearchResultsCache
  14. {
  15. /**
  16. * SHA256 hash of the request URI (including query parameters).
  17. */
  18. #[ORM\Id]
  19. #[ORM\Column(name: 'cache_key', type: 'string', length: 64)]
  20. private string $cacheKey;
  21. /**
  22. * Full rendered HTML response.
  23. */
  24. #[ORM\Column(name: 'html_content', type: 'text')]
  25. private string $htmlContent;
  26. #[ORM\Column(name: 'created_at', type: 'datetime')]
  27. private DateTime $createdAt;
  28. #[ORM\Column(name: 'expires_at', type: 'datetime')]
  29. private DateTime $expiresAt;
  30. public function __construct(
  31. string $cacheKey,
  32. string $htmlContent,
  33. DateTime $createdAt,
  34. DateTime $expiresAt
  35. ) {
  36. $this->cacheKey = $cacheKey;
  37. $this->htmlContent = $htmlContent;
  38. $this->createdAt = $createdAt;
  39. $this->expiresAt = $expiresAt;
  40. }
  41. public function getCacheKey(): string
  42. {
  43. return $this->cacheKey;
  44. }
  45. public function getHtmlContent(): string
  46. {
  47. return $this->htmlContent;
  48. }
  49. public function setHtmlContent(string $htmlContent): self
  50. {
  51. $this->htmlContent = $htmlContent;
  52. return $this;
  53. }
  54. public function getCreatedAt(): DateTime
  55. {
  56. return $this->createdAt;
  57. }
  58. public function getExpiresAt(): DateTime
  59. {
  60. return $this->expiresAt;
  61. }
  62. public function setExpiresAt(DateTime $expiresAt): self
  63. {
  64. $this->expiresAt = $expiresAt;
  65. return $this;
  66. }
  67. public function isExpired(DateTime $now): bool
  68. {
  69. return $now > $this->expiresAt;
  70. }
  71. }