Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Let's create a timestamp service, which has the following interface:
- invalidate($tag) or markAsOutdated($tag) -- invalidate one
- getLastWriteTimestamp($tag) -- load one
- getLastWriteTimestamps($tags) -- load multiple
Let's base it on ChainedFast implementation, which turns out to be very solid (after re-review):
/**
* Marks the fast cache bin as outdated because of a write.
*/
protected function markAsOutdated() {
// Clocks on a single server can drift. Multiple servers may have slightly
// differing opinions about the current time. Given that, do not assume
// 'now' on this server is always later than our stored timestamp.
// Also add 1 millisecond, to ensure that caches written earlier in the same
// millisecond are invalidated. It is possible that caches will be later in
// the same millisecond and are then incorrectly invalidated, but that only
// costs one additional roundtrip to the persistent cache.
$now = round(microtime(TRUE) + 0.001, 3);
if ($now > $this
->getLastWriteTimestamp()) {
$this->lastWriteTimestamp = $now;
$this->consistentBackend
->set(self::LAST_WRITE_TIMESTAMP_PREFIX . $this->bin, $this->lastWriteTimestamp);
}
}
but let's make the 0.001 configurable and injectable as parameter and maybe come up with a good format to allow min/max() to work on the values (needed for cache tags).
Comment | File | Size | Author |
---|---|---|---|
#5 | 2996621-timestamp-invalidator-service-4.interdiff.txt | 2.13 KB | bdragon |
#5 | 2996621-timestamp-invalidator-service-4.patch | 5.3 KB | bdragon |
Comments
Comment #2
bdragon CreditAttribution: bdragon at Tag1 Consulting for Acquia commentedHere's the timestamp invalidator service parts, split off of the #2989601: Support for cache tags natively in memcache patch.
Comment #3
bdragon CreditAttribution: bdragon at Tag1 Consulting for Acquia commentedAdd a way to access the current timestamp so the users of this interface can implement cooldown policies.
Comment #4
bdragon CreditAttribution: bdragon at Tag1 Consulting for Acquia commentedSimplify the service definition by taking a factory instead.
Fix missing newlines at end of file.
Comment #5
bdragon CreditAttribution: bdragon at Tag1 Consulting for Acquia commentedTidying up documentation relating to the tolerance.
Comment #6
Fabianx CreditAttribution: Fabianx at Tag1 Consulting for Acquia commentedRTBC - looks great
Comment #8
bdragon CreditAttribution: bdragon at Tag1 Consulting for Acquia commentedcommitted, thanks.
Comment #9
bdragon CreditAttribution: bdragon at Tag1 Consulting for Acquia commented