3 namespace Drupal\memcache\Invalidator;
6 * Class TimestampInvalidatorBase.
8 * Base class for timestamp-based tag invalidation.
10 * @package Drupal\memcache\Invalidator
12 abstract class TimestampInvalidatorBase implements TimestampInvalidatorInterface {
15 * Allowed timestamp slop.
22 * TimestampInvalidatorBase constructor.
24 * @param float $tolerance
25 * Allowed clock skew between servers, in decimal seconds.
27 public function __construct($tolerance = 0.001) {
28 $this->tolerance = $tolerance;
32 * Mark a tag as outdated.
35 * Tag to mark as outdated.
38 * New timestamp for tag.
40 protected function markAsOutdated($tag) {
41 $now = $this->getCurrentTimestamp($this->tolerance);
42 $current = $this->getLastInvalidationTimestamp($tag);
43 if ($now > $current) {
44 $this->writeTimestamp($tag, $now);
55 public function getCurrentTimestamp($offset = 0.0) {
56 // @todo Eventually we might want to use a time service instead of microtime().
57 // Unfortunately, TimeInterface needs a request object and we don't have
58 // that in the bootstrap container.
59 return round(microtime(TRUE) + $offset, 3);
65 abstract public function invalidateTimestamp($tag);
70 abstract public function getLastInvalidationTimestamps(array $tags);
73 * Write an updated timestamp for a tag to the backend.
77 * @param float $timestamp
78 * New timestamp to write.
81 * Success or failure from backend.
83 abstract protected function writeTimestamp($tag, $timestamp);