SignalCache.php in Ultimate Cron 8.2
File
src/Signal/SignalCache.php
View source
<?php
namespace Drupal\ultimate_cron\Signal;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Lock\LockBackendInterface;
use Drupal\ultimate_cron\Signal\SignalInterface;
class SignalCache implements SignalInterface {
public $cacheBackend;
public $lockBackend;
public function __construct(CacheBackendInterface $cache_backend, LockBackendInterface $lock_backend) {
$this->cacheBackend = $cache_backend;
$this->lockBackend = $lock_backend;
}
public function peek($job_id, $signal) {
$cache = $this->cacheBackend
->get("signal-{$job_id}-{$signal}");
if ($cache) {
$flushed = $this->cacheBackend
->get("flushed-{$job_id}");
if (!$flushed || $cache->created > $flushed->created) {
return $cache->data;
}
}
return FALSE;
}
public function get($job_id, $signal) {
if ($this->lockBackend
->acquire("signal-{$job_id}-{$signal}")) {
$result = self::peek($job_id, $signal);
self::clear($job_id, $signal);
$this->lockBackend
->release("signal-{$job_id}-{$signal}");
return $result;
}
return FALSE;
}
public function set($job_id, $signal) {
$this->cacheBackend
->set("signal-{$job_id}-{$signal}", TRUE);
}
public function clear($job_id, $signal) {
$this->cacheBackend
->delete("signal-{$job_id}-{$signal}");
}
public function flush($job_id) {
$this->cacheBackend
->set("flushed-{$job_id}", microtime(TRUE));
}
}