You are here

public function State::incrementTagPurgeDailyCount in CloudFlare 8

Increment the count of tag purges done today.

Overrides CloudFlareStateInterface::incrementTagPurgeDailyCount

See also

https://support.cloudflare.com/hc/en-us/articles/206596608-How-to-Purge-...

File

src/State.php, line 48

Class

State
Tracks rate limits associated with CloudFlare Api.

Namespace

Drupal\cloudflare

Code

public function incrementTagPurgeDailyCount() {
  $count = $this->state
    ->get(self::TAG_PURGE_DAILY_COUNT);
  $last_recorded_timestamp = $this->state
    ->get(self::TAG_PURGE_DAILY_COUNT_START);
  $last_recorded_timestamp = is_null($last_recorded_timestamp) ? new DateTime('2001-01-01') : $last_recorded_timestamp;
  $now = $this->timestamper
    ->now();
  $todays_date = $now
    ->format('Y-m-d');
  $last_recorded_date = $last_recorded_timestamp
    ->format('Y-m-d');
  if (empty($last_recorded_timestamp) || $last_recorded_date != $todays_date) {
    $this->state
      ->set(self::TAG_PURGE_DAILY_COUNT, 1);
    $this->state
      ->set(self::TAG_PURGE_DAILY_COUNT_START, $now);
  }
  else {
    $count++;
    $this->state
      ->set(self::TAG_PURGE_DAILY_COUNT, $count);
  }
}