Verified Commit 1f1d1ab3 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3436804 by longwave: CacheCollector::normalizeLockName() is pointless

parent 8d5b54ef
Loading
Loading
Loading
Loading
Loading
+1 −26
Original line number Diff line number Diff line
@@ -3,7 +3,6 @@
namespace Drupal\Core\Cache;

use Drupal\Component\Assertion\Inspector;
use Drupal\Component\Utility\Crypt;
use Drupal\Core\DestructableInterface;
use Drupal\Core\Lock\LockBackendInterface;

@@ -229,7 +228,7 @@ protected function updateCache($lock = TRUE) {

    // Lock cache writes to help avoid stampedes.
    $cid = $this->getCid();
    $lock_name = $this->normalizeLockName($cid . ':' . __CLASS__);
    $lock_name = $cid . ':' . __CLASS__;
    if (!$lock || $this->lock->acquire($lock_name)) {
      // Set and delete operations invalidate the cache item. Try to also load
      // an eventually invalidated cache entry, only update an invalidated cache
@@ -273,30 +272,6 @@ protected function updateCache($lock = TRUE) {
    $this->keysToRemove = [];
  }

  /**
   * Normalizes a cache ID in order to comply with database limitations.
   *
   * @param string $cid
   *   The passed in cache ID.
   *
   * @return string
   *   An ASCII-encoded cache ID that is at most 255 characters long.
   */
  protected function normalizeLockName($cid) {
    // Nothing to do if the ID is a US ASCII string of 255 characters or less.
    $cid_is_ascii = mb_check_encoding($cid, 'ASCII');
    if (strlen($cid) <= 255 && $cid_is_ascii) {
      return $cid;
    }
    // Return a string that uses as much as possible of the original cache ID
    // with the hash appended.
    $hash = Crypt::hashBase64($cid);
    if (!$cid_is_ascii) {
      return $hash;
    }
    return substr($cid, 0, 255 - strlen($hash)) . $hash;
  }

  /**
   * {@inheritdoc}
   */