You are here

public function InvalidationBase::setProperty in Purge 8.3

Set a purger specific property.

Once ::setStateContext() has been called, purgers can call ::setProperty() and ::getProperty() to store specific metadata on the invalidation. The most common usecase for setting properties is for multi-step cache invalidation, for instance CDNs returning IDs to check against later.

Parameters

string $key: The key of the property to set, unique to the current purger context.

mixed $value: The value of the property.

Throws

\LogicException Thrown when operating in general context, call ::setStateContext() first.

Overrides InvalidationInterface::setProperty

File

src/Plugin/Purge/Invalidation/InvalidationBase.php, line 96

Class

InvalidationBase
Provides base implementations for the invalidation object.

Namespace

Drupal\purge\Plugin\Purge\Invalidation

Code

public function setProperty($key, $value) {
  if (is_null($this->context)) {
    throw new \LogicException('Call ::setStateContext() before setting properties!');
  }
  if (!isset($this->properties[$this->context])) {
    $this->properties[$this->context] = [];
  }
  $this->properties[$this->context][$key] = $value;
}