Class cache_context.session - Source Code

Primary tabs

API docs: https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Cache!Context!SessionCacheContext.php/11.3.x

GitLab: https://git.drupalcode.org/project/drupal/-/blob/11.3.x/core/lib/Drupal/Core/Cache/Context/SessionCacheContext.php

Location: /core/lib/Drupal/Core/Cache/Context/SessionCacheContext.php

    
        
namespace Drupal\Core\Cache\Context;

use Drupal\Component\Utility\Crypt;

/**
 * Defines the SessionCacheContext service, for "per session" caching.
 *
 * Cache context ID: 'session'.
 */
class SessionCacheContext extends RequestStackCacheContextBase {

  /**
   * {@inheritdoc}
   */
  public static function getLabel() {
    return t('Session');
  }

  /**
   * {@inheritdoc}
   */
  public function getContext() {
    return Crypt::hashBase64($this->requestStack->getSession()->getId());
  }

}