LocaleLookup::getCid

protected LocaleLookup::getCid()

Gets the cache ID.

Return value

string

Overrides CacheCollector::getCid

File

core/modules/locale/src/LocaleLookup.php, line 109

Class

LocaleLookup
A cache collector to allow for dynamic building of the locale cache.

Namespace

Drupal\locale

Code

protected function getCid() {
  if (!isset($this->cid)) {
    // Add the current user's role IDs to the cache key, this ensures that,
    // for example, strings for admin menu items and settings forms are not
    // cached for anonymous users.
    $user = \Drupal::currentUser();
    $rids = $user ? implode(':', $user->getRoles()) : '';
    $this->cid = "locale:{$this->langcode}:{$this->context}:$rids";

    // Getting the roles from the current user might have resulted in t()
    // calls that attempted to get translations from the locale cache. In that
    // case they would not go into this method again as
    // CacheCollector::lazyLoadCache() already set the loaded flag. They would
    // however call resolveCacheMiss() and add that string to the list of
    // cache misses that need to be written into the cache. Prevent that by
    // resetting that list. All that happens in such a case are a few uncached
    // translation lookups.
    $this->keysToPersist = array();
  }
  return $this->cid;
}
doc_Drupal
2016-10-29 09:24:06
Comments
Leave a Comment

Please login to continue.