UserCacheContext.php

Same filename in other branches
  1. 9 core/lib/Drupal/Core/Cache/Context/UserCacheContext.php
  2. 8.9.x core/lib/Drupal/Core/Cache/Context/UserCacheContext.php
  3. 10 core/lib/Drupal/Core/Cache/Context/UserCacheContext.php

Namespace

Drupal\Core\Cache\Context

File

core/lib/Drupal/Core/Cache/Context/UserCacheContext.php

View source
<?php

namespace Drupal\Core\Cache\Context;

use Drupal\Core\Cache\CacheableMetadata;

/**
 * Defines the UserCacheContext service, for "per user" caching.
 *
 * Cache context ID: 'user'.
 */
class UserCacheContext extends UserCacheContextBase implements CacheContextInterface {
    
    /**
     * {@inheritdoc}
     */
    public static function getLabel() {
        return t('User');
    }
    
    /**
     * {@inheritdoc}
     */
    public function getContext() {
        return $this->user
            ->id();
    }
    
    /**
     * {@inheritdoc}
     */
    public function getCacheableMetadata() {
        return new CacheableMetadata();
    }

}

Classes

Title Deprecated Summary
UserCacheContext Defines the UserCacheContext service, for "per user" caching.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.