You are here

public function Users::refreshCache in Rocket.Chat 8.2

Overrides CollectionInterface::refreshCache

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

File

modules/rocket_chat_api/src/RocketChat/Collection/Users.php, line 61

Class

Users

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 Users Cache due to stale Cache  (timeout)");
    $forceReload = TRUE;
  }
  if ($forceReload) {
    $users = [];
    $found = self::getAllUsersBatched($this->apiClient, $users);
    $userIds = [];
    foreach ($users as $user) {
      $userIds[] = $user['_id'];
      $this->state
        ->set(self::USER . $user['_id'], $user);
    }
    $this->state
      ->set(self::LIST, $userIds);
    $this->state
      ->set(self::UPDATE, $now);
  }
}