You are here

public function Groups::refreshCache in Rocket.Chat 8.2

Overrides CollectionInterface::refreshCache

1 call to Groups::refreshCache()
Groups::getCache in modules/rocket_chat_api/src/RocketChat/Collection/Groups.php

File

modules/rocket_chat_api/src/RocketChat/Collection/Groups.php, line 53

Class

Groups

Namespace

Drupal\rocket_chat_api\RocketChat\Collection

Code

public function refreshCache($forceReload = FALSE) {
  $lastUpdate = $this->state
    ->get(self::UPDATE, 0);
  $now = time();
  if ($now - $lastUpdate >= 3600 * 24 * 7) {
    $this->Logger
      ->info("Refreshing Groups Cache due to stale Cache  (timeout)");
    $forceReload = TRUE;
  }
  if ($forceReload) {
    $groups = [];
    $found = Channel::getAllGroupsBatched($this->apiClient, $groups);
    $groupIds = [];
    foreach ($groups as $group) {
      $groupIds[] = $group['_id'];
      $this->state
        ->set(self::GROUP . $group['_id'], $group);
    }
    $this->state
      ->set(self::LIST, $groupIds);
    $this->state
      ->set(self::UPDATE, $now);
  }
}