You are here

final protected function DrupalMemcachedBase::getBinIndex in Memcache Storage 8

Returns cache bin index. This index is part of memcache key and changes if cache bin should be cleared.

Parameters

$cache_bin: Name of the cache bin.

1 call to DrupalMemcachedBase::getBinIndex()
DrupalMemcachedBase::itemKey in src/DrupalMemcachedBase.php
Return the formatted cache key as it will be stored in memcached.

File

src/DrupalMemcachedBase.php, line 293

Class

DrupalMemcachedBase
Class DrupalMemcachedBase

Namespace

Drupal\memcache_storage

Code

protected final function getBinIndex($cache_bin) {

  // If the variable is not initialized - then make an attempt to load
  // the data from cache.
  if (!isset($this->bin_indexes)) {
    $this->bin_indexes = [];

    // An attempt to get bin indexes from cache.
    $cache = $this
      ->get('memcache_storage_bin_indexes');
    if (!empty($cache->data)) {
      $this->bin_indexes = $cache->data;
    }
  }

  // If info about bin doesn't exist, then initialize it with the default
  // value.
  if (empty($this->bin_indexes[$cache_bin])) {
    $this->bin_indexes[$cache_bin] = 1;

    // Initial index value.
    $this
      ->set('memcache_storage_bin_indexes', $this->bin_indexes, 0);
  }
  return $this->bin_indexes[$cache_bin];
}