ProgressMemcache.php in Ultimate Cron 8.2
File
src/Progress/ProgressMemcache.php
View source
<?php
namespace Drupal\ultimate_cron\Progress;
use Drupal\ultimate_cron\Progress;
class ProgressMemcache {
public $name;
public $progressUpdated = 0;
public $interval = 1;
public static $instances = array();
public function __construct($name, $interval = 1) {
$this->name = $name;
$this->interval = $interval;
}
public static function factory($name, $interval = 1) {
if (!isset(self::$instances[$name])) {
self::$instances[$name] = new ProgressMemcache($name, $interval);
}
self::$instances[$name]->interval = $interval;
return self::$instances[$name];
}
public function getProgress() {
$name = 'uc-progress:' . $this->name;
$bin = variable_get('ultimate_cron_progress_memcache_bin', 'progress');
return dmemcache_get($name, $bin);
}
public static function getProgressMultiple($names) {
$keys = array();
foreach ($names as $name) {
$keys[] = 'uc-progress:' . $name;
}
$bin = variable_get('ultimate_cron_progress_memcache_bin', 'progress');
$values = dmemcache_get_multi($keys, $bin);
$result = array();
foreach ($names as $name) {
$result[$name] = isset($values['uc-progress:' . $name]) ? $values['uc-progress:' . $name] : FALSE;
}
return $result;
}
public function setProgress($progress) {
if (microtime(TRUE) >= $this->progressUpdated + $this->interval) {
$name = 'uc-progress:' . $this->name;
$bin = variable_get('ultimate_cron_progress_memcache_bin', 'progress');
dmemcache_set($name, $progress, 0, $bin);
$this->progressUpdated = microtime(TRUE);
return TRUE;
}
return FALSE;
}
}