Files
domain-watchdog/src/Service/StatService.php

27 lines
480 B
PHP
Raw Normal View History

2024-08-25 03:31:09 +02:00
<?php
namespace App\Service;
use Psr\Cache\CacheItemPoolInterface;
readonly class StatService
{
public function __construct(
private CacheItemPoolInterface $pool
) {
}
public function incrementStat(string $key): bool
{
try {
$item = $this->pool->getItem($key);
$item->set(($item->get() ?? 0) + 1);
return $this->pool->save($item);
} catch (\Throwable) {
}
return false;
}
}