SiteCacheContext.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace Drupal\Core\Cache\Context;
  3. use Drupal\Core\Cache\CacheableMetadata;
  4. /**
  5. * Defines the SiteCacheContext service, for "per site" caching.
  6. *
  7. * Cache context ID: 'url.site'.
  8. *
  9. * A "site" is defined as the combination of URI scheme, domain name, port and
  10. * base path. It allows for varying between the *same* site being accessed via
  11. * different entry points. (Different sites in a multisite setup have separate
  12. * databases.) For example: http://example.com and http://www.example.com.
  13. *
  14. * @see \Symfony\Component\HttpFoundation\Request::getSchemeAndHttpHost()
  15. * @see \Symfony\Component\HttpFoundation\Request::getBaseUrl()
  16. */
  17. class SiteCacheContext extends RequestStackCacheContextBase implements CacheContextInterface {
  18. /**
  19. * {@inheritdoc}
  20. */
  21. public static function getLabel() {
  22. return t('Site');
  23. }
  24. /**
  25. * {@inheritdoc}
  26. */
  27. public function getContext() {
  28. $request = $this->requestStack->getCurrentRequest();
  29. return $request->getSchemeAndHttpHost() . $request->getBaseUrl();
  30. }
  31. /**
  32. * {@inheritdoc}
  33. */
  34. public function getCacheableMetadata() {
  35. return new CacheableMetadata();
  36. }
  37. }