Commit aa265f1d authored by Benji Fisher's avatar Benji Fisher Committed by Jakob P
Browse files

Issue #3302086 by benjifisher, japerry, Damien LAGUERRE: After upgrade to 2.4,...

Issue #3302086 by benjifisher, japerry, Damien LAGUERRE: After upgrade to 2.4, Drupal 9.4.5 and PHP 8.0.21, \Drupal::$container is not initialized yet. \Drupal::setContainer() must be called with a real container
parent 7d25b18b
Loading
Loading
Loading
Loading
+15 −11
Original line number Diff line number Diff line
@@ -74,13 +74,6 @@ class MemcacheBackend implements CacheBackendInterface {
   */
  protected $timestampInvalidator;

  /**
   * The DateTime Service.
   *
   * @var \Drupal\Component\Datetime\TimeInterface
   */
  protected $time;

  /**
   * Constructs a MemcacheBackend object.
   *
@@ -93,12 +86,11 @@ class MemcacheBackend implements CacheBackendInterface {
   * @param \Drupal\memcache\Invalidator\TimestampInvalidatorInterface $timestamp_invalidator
   *   The timestamp invalidation provider.
   */
  public function __construct($bin, DrupalMemcacheInterface $memcache, CacheTagsChecksumInterface $checksum_provider, TimestampInvalidatorInterface $timestamp_invalidator, $time_service = NULL) {
  public function __construct($bin, DrupalMemcacheInterface $memcache, CacheTagsChecksumInterface $checksum_provider, TimestampInvalidatorInterface $timestamp_invalidator) {
    $this->bin = $bin;
    $this->memcache = $memcache;
    $this->checksumProvider = $checksum_provider;
    $this->timestampInvalidator = $timestamp_invalidator;
    $this->time = $time_service ?? \Drupal::time();

    $this->ensureBinDeletionTimeIsSet();
  }
@@ -124,6 +116,18 @@ class MemcacheBackend implements CacheBackendInterface {
    }
  }

  /**
   * Returns the timestamp for the current request.
   *
   * @return int
   *   A Unix timestamp.
   *
   * @see Drupal\Component\Datetime\Time::getRequestTime()
   */
  public static function getRequestTime() {
    return (int) $_SERVER['REQUEST_TIME'] ?? time();
  }

  /**
   * {@inheritdoc}
   */
@@ -192,7 +196,7 @@ class MemcacheBackend implements CacheBackendInterface {
    $cache->valid = TRUE;

    // Items that have expired are invalid.
    if ($cache->expire != CacheBackendInterface::CACHE_PERMANENT && $cache->expire <= $this->time->getRequestTime()) {
    if ($cache->expire != CacheBackendInterface::CACHE_PERMANENT && $cache->expire <= static::getRequestTime()) {
      $cache->valid = FALSE;
    }

@@ -374,7 +378,7 @@ class MemcacheBackend implements CacheBackendInterface {
  public function invalidateMultiple(array $cids) {
    foreach ($cids as $cid) {
      if ($item = $this->get($cid)) {
        $item->expire = $this->time->getRequestTime() - 1;
        $item->expire = static::getRequestTime() - 1;
        $this->memcache->set($cid, $item);
      }
    }
+2 −12
Original line number Diff line number Diff line
@@ -2,7 +2,6 @@

namespace Drupal\memcache;

use Drupal\Component\Datetime\TimeInterface;
use Drupal\Core\Cache\CacheFactoryInterface;
use Drupal\Core\Cache\CacheTagsChecksumInterface;
use Drupal\memcache\Driver\MemcacheDriverFactory;
@@ -34,13 +33,6 @@ class MemcacheBackendFactory implements CacheFactoryInterface {
   */
  protected $timestampInvalidator;

  /**
   * Drupal DateTime Service.
   *
   * @var \Drupal\Component\Datetime\TimeInterface
   */
  protected $time;

  /**
   * Constructs the MemcacheBackendFactory object.
   *
@@ -51,11 +43,10 @@ class MemcacheBackendFactory implements CacheFactoryInterface {
   * @param \Drupal\memcache\Invalidator\TimestampInvalidatorInterface $timestamp_invalidator
   *   The timestamp invalidation provider.
   */
  public function __construct(MemcacheDriverFactory $memcache_factory, CacheTagsChecksumInterface $checksum_provider, TimestampInvalidatorInterface $timestamp_invalidator, TimeInterface $time_service) {
  public function __construct(MemcacheDriverFactory $memcache_factory, CacheTagsChecksumInterface $checksum_provider, TimestampInvalidatorInterface $timestamp_invalidator) {
    $this->memcacheFactory = $memcache_factory;
    $this->checksumProvider = $checksum_provider;
    $this->timestampInvalidator = $timestamp_invalidator;
    $this->time = $time_service;
  }

  /**
@@ -72,8 +63,7 @@ class MemcacheBackendFactory implements CacheFactoryInterface {
      $bin,
      $this->memcacheFactory->get($bin),
      $this->checksumProvider,
      $this->timestampInvalidator,
      $this->time
      $this->timestampInvalidator
    );
  }