<?php
declare(strict_types=1);
namespace JanusHercules\RecurrentJobsCheapSearch\Domain\Entity;
use DateTime;
use Doctrine\ORM\Mapping as ORM;
/**
* Caches full HTML responses for anonymous search results during cheap search mode.
* This enables response caching across all app servers in the cluster.
*/
#[ORM\Entity]
#[ORM\Table(name: 'cheap_search_anonymous_results_cache')]
#[ORM\Index(name: 'csarc_expires_at_idx', columns: ['expires_at'])]
class AnonymousSearchResultsCache
{
/**
* SHA256 hash of the request URI (including query parameters).
*/
#[ORM\Id]
#[ORM\Column(name: 'cache_key', type: 'string', length: 64)]
private string $cacheKey;
/**
* Full rendered HTML response.
*/
#[ORM\Column(name: 'html_content', type: 'text')]
private string $htmlContent;
#[ORM\Column(name: 'created_at', type: 'datetime')]
private DateTime $createdAt;
#[ORM\Column(name: 'expires_at', type: 'datetime')]
private DateTime $expiresAt;
public function __construct(
string $cacheKey,
string $htmlContent,
DateTime $createdAt,
DateTime $expiresAt
) {
$this->cacheKey = $cacheKey;
$this->htmlContent = $htmlContent;
$this->createdAt = $createdAt;
$this->expiresAt = $expiresAt;
}
public function getCacheKey(): string
{
return $this->cacheKey;
}
public function getHtmlContent(): string
{
return $this->htmlContent;
}
public function setHtmlContent(string $htmlContent): self
{
$this->htmlContent = $htmlContent;
return $this;
}
public function getCreatedAt(): DateTime
{
return $this->createdAt;
}
public function getExpiresAt(): DateTime
{
return $this->expiresAt;
}
public function setExpiresAt(DateTime $expiresAt): self
{
$this->expiresAt = $expiresAt;
return $this;
}
public function isExpired(DateTime $now): bool
{
return $now > $this->expiresAt;
}
}