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).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Fabianx created an issue. See original summary.

bdragon’s picture

Status: Active » Needs review
FileSize
4.5 KB

Here's the timestamp invalidator service parts, split off of the #2989601: Support for cache tags natively in memcache patch.

bdragon’s picture

Add a way to access the current timestamp so the users of this interface can implement cooldown policies.

bdragon’s picture

Simplify the service definition by taking a factory instead.
Fix missing newlines at end of file.

bdragon’s picture

Tidying up documentation relating to the tolerance.

Fabianx’s picture

Status: Needs review » Reviewed & tested by the community

RTBC - looks great

  • bdragon authored de03e20 on 8.x-2.x
    Issue #2996621 by bdragon, Fabianx: Create timestamp service, which both...
bdragon’s picture

committed, thanks.

bdragon’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.