You are here

public function Channels::refreshCache in Rocket.Chat 8.2

Overrides CollectionInterface::refreshCache

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

File

modules/rocket_chat_api/src/RocketChat/Collection/Channels.php, line 59

Class

Channels

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 Channels Cache due to stale Cache  (timeout)");
    $forceReload = TRUE;
  }
  if ($forceReload) {
    $channels = [];
    $found = Channel::getAllChannelsBatched($this->apiClient, $channels);
    $channelIds = [];
    foreach ($channels as $channel) {
      $this->state
        ->set(self::CHANNEL . $channel['_id'], $channel);
    }
    $this->state
      ->set(self::LIST, $channelIds);
    $this->state
      ->set(self::UPDATE, $now);
  }
}