<?php

namespace App\Services;

use App\Core\Database;

class HomepageCacheService
{

public static function get(
int $conferenceId
)
{

$db=
Database::getInstance();

$stmt=
$db
->prepare("

SELECT
html_cache

FROM
conference_home_cache

WHERE conference_id=?

LIMIT 1

");

$stmt
->execute([

$conferenceId

]);

return
$stmt
->fetchColumn();

}

public static function put(
int $conferenceId,
string $html
)
{

$db=
Database::getInstance();

$db
->prepare("

REPLACE INTO
conference_home_cache(

conference_id,

cache_key,

html_cache,

cache_hash

)

VALUES(

?,

'homepage',

?,

SHA2(?,256)

)

")

->execute([

$conferenceId,

$html,

$html

]);

}

public static function clear(
int $conferenceId
)
{

$db=
Database::getInstance();

$db
->prepare("

DELETE

FROM
conference_home_cache

WHERE conference_id=?

")

->execute([

$conferenceId

]);

}

}
