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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.