You are here

class CacheDataCollector in Devel 8.2

Same name and namespace in other branches
  1. 8.3 webprofiler/src/DataCollector/CacheDataCollector.php \Drupal\webprofiler\DataCollector\CacheDataCollector
  2. 8 webprofiler/src/DataCollector/CacheDataCollector.php \Drupal\webprofiler\DataCollector\CacheDataCollector
  3. 4.x webprofiler/src/DataCollector/CacheDataCollector.php \Drupal\webprofiler\DataCollector\CacheDataCollector

Collects the used cache bins and cache CIDs.

Hierarchy

Expanded class hierarchy of CacheDataCollector

3 files declare their use of CacheDataCollector
CacheBackendWrapper.php in webprofiler/src/Cache/CacheBackendWrapper.php
CacheDataCollectorTest.php in webprofiler/tests/src/Unit/DataCollector/CacheDataCollectorTest.php
CacheFactoryWrapper.php in webprofiler/src/Cache/CacheFactoryWrapper.php
1 string reference to 'CacheDataCollector'
webprofiler.services.yml in webprofiler/webprofiler.services.yml
webprofiler/webprofiler.services.yml
1 service uses CacheDataCollector
webprofiler.cache in webprofiler/webprofiler.services.yml
Drupal\webprofiler\DataCollector\CacheDataCollector

File

webprofiler/src/DataCollector/CacheDataCollector.php, line 14

Namespace

Drupal\webprofiler\DataCollector
View source
class CacheDataCollector extends DataCollector implements DrupalDataCollectorInterface {
  use StringTranslationTrait, DrupalDataCollectorTrait;
  const WEBPROFILER_CACHE_HIT = 'bin_cids_hit';
  const WEBPROFILER_CACHE_MISS = 'bin_cids_miss';

  /**
   * {@inheritdoc}
   */
  public function collect(Request $request, Response $response, \Exception $exception = NULL) {
  }

  /**
   *
   */
  public function __construct() {
    $this->data['total'][CacheDataCollector::WEBPROFILER_CACHE_HIT] = 0;
    $this->data['total'][CacheDataCollector::WEBPROFILER_CACHE_MISS] = 0;
    $this->data['cache'] = [];
  }

  /**
   * Registers a cache get on a specific cache bin.
   *
   * @param $cache
   */
  public function registerCacheHit($bin, $cache) {
    $current = isset($this->data['cache'][$bin][$cache->cid]) ? $this->data['cache'][$bin][$cache->cid] : NULL;
    if (!$current) {
      $current = $cache;
      $current->{CacheDataCollector::WEBPROFILER_CACHE_HIT} = 0;
      $current->{CacheDataCollector::WEBPROFILER_CACHE_MISS} = 0;
      $this->data['cache'][$bin][$cache->cid] = $current;
    }
    $current->{CacheDataCollector::WEBPROFILER_CACHE_HIT}++;
    $this->data['total'][CacheDataCollector::WEBPROFILER_CACHE_HIT]++;
  }

  /**
   * Registers a cache get on a specific cache bin.
   *
   * @param $bin
   * @param $cid
   */
  public function registerCacheMiss($bin, $cid) {
    $current = isset($this->data['cache'][$bin][$cid]) ? $this->data['cache'][$bin][$cid] : NULL;
    if (!$current) {
      $current = new \StdClass();
      $current->{CacheDataCollector::WEBPROFILER_CACHE_HIT} = 0;
      $current->{CacheDataCollector::WEBPROFILER_CACHE_MISS} = 0;
      $this->data['cache'][$bin][$cid] = $current;
    }
    $current->{CacheDataCollector::WEBPROFILER_CACHE_MISS}++;
    $this->data['total'][CacheDataCollector::WEBPROFILER_CACHE_MISS]++;
  }

  /**
   * Callback to return the total amount of requested cache CIDS.
   *
   * @param string $type
   *
   * @return int
   */
  public function getCacheCidsCount($type) {
    return $this->data['total'][$type];
  }

  /**
   * Callback to return the total amount of hit cache CIDS.
   *
   * @return int
   */
  public function getCacheHitsCount() {
    return $this
      ->getCacheCidsCount(CacheDataCollector::WEBPROFILER_CACHE_HIT);
  }

  /**
   * Callback to return the total amount of miss cache CIDS.
   *
   * @return int
   */
  public function getCacheMissesCount() {
    return $this
      ->getCacheCidsCount(CacheDataCollector::WEBPROFILER_CACHE_MISS);
  }

  /**
   * Callback to return the total amount of hit cache CIDs keyed by bin.
   *
   * @param $type
   *
   * @return array
   */
  public function cacheCids($type) {
    $hits = [];
    foreach ($this->data['cache'] as $bin => $caches) {
      $hits[$bin] = 0;
      foreach ($caches as $cid => $cache) {
        $hits[$bin] += $cache->{$type};
      }
    }
    return $hits;
  }

  /**
   * Callback to return hit cache CIDs keyed by bin.
   *
   * @return array
   */
  public function getCacheHits() {
    return $this
      ->cacheCids(CacheDataCollector::WEBPROFILER_CACHE_HIT);
  }

  /**
   * Callback to return miss cache CIDs keyed by bin.
   *
   * @return array
   */
  public function getCacheMisses() {
    return $this
      ->cacheCids(CacheDataCollector::WEBPROFILER_CACHE_MISS);
  }

  /**
   * {@inheritdoc}
   */
  public function getName() {
    return 'cache';
  }

  /**
   * {@inheritdoc}
   */
  public function getTitle() {
    return $this
      ->t('Cache');
  }

  /**
   * {@inheritdoc}
   */
  public function getPanelSummary() {
    return $this
      ->t('Hit: @cache_hit, miss: @cache_miss', [
      '@cache_hit' => $this
        ->getCacheCidsCount(CacheDataCollector::WEBPROFILER_CACHE_HIT),
      '@cache_miss' => $this
        ->getCacheCidsCount(CacheDataCollector::WEBPROFILER_CACHE_MISS),
    ]);
  }

  /**
   * {@inheritdoc}
   */
  public function getIcon() {
    return 'iVBORw0KGgoAAAANSUhEUgAAABQAAAAcCAYAAABh2p9gAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyRpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYxIDY0LjE0MDk0OSwgMjAxMC8xMi8wNy0xMDo1NzowMSAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNS4xIE1hY2ludG9zaCIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDo2Njc3QTVEQTkxNkMxMUUzQjA3OUEzQTNEMUVGMjVDOCIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDo2Njc3QTVEQjkxNkMxMUUzQjA3OUEzQTNEMUVGMjVDOCI+IDx4bXBNTTpEZXJpdmVkRnJvbSBzdFJlZjppbnN0YW5jZUlEPSJ4bXAuaWlkOjRGQTVBQzYxOTE2QzExRTNCMDc5QTNBM0QxRUYyNUM4IiBzdFJlZjpkb2N1bWVudElEPSJ4bXAuZGlkOjRGQTVBQzYyOTE2QzExRTNCMDc5QTNBM0QxRUYyNUM4Ii8+IDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY+IDwveDp4bXBtZXRhPiA8P3hwYWNrZXQgZW5kPSJyIj8+BsBwAAAAAJtJREFUeNpi/P//PwM1ARMDlcEIMdDBweEZjM0IihSgwEx8Gg4cOJCOrhGHOimqe5kF2QVYvDITl0vQvQwTo4oLkS1gQrPpPwiTEBkY6pnwKJ5JyOskJRvkcMUVxjgjhRhDsUUGSQZu3rwZb1j6+voyjhYOI9VAFmKTBTC3oMsTbyAx+RndAqxejo2NJdmL6HoYR6vRwWcgQIABAOn0PsqqgQzcAAAAAElFTkSuQmCC';
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CacheDataCollector::cacheCids public function Callback to return the total amount of hit cache CIDs keyed by bin.
CacheDataCollector::collect public function Collects data for the given Request and Response.
CacheDataCollector::getCacheCidsCount public function Callback to return the total amount of requested cache CIDS.
CacheDataCollector::getCacheHits public function Callback to return hit cache CIDs keyed by bin.
CacheDataCollector::getCacheHitsCount public function Callback to return the total amount of hit cache CIDS.
CacheDataCollector::getCacheMisses public function Callback to return miss cache CIDs keyed by bin.
CacheDataCollector::getCacheMissesCount public function Callback to return the total amount of miss cache CIDS.
CacheDataCollector::getIcon public function Returns the collector icon in base64 format. Overrides DrupalDataCollectorInterface::getIcon
CacheDataCollector::getName public function Returns the name of the collector. Overrides DrupalDataCollectorInterface::getName
CacheDataCollector::getPanelSummary public function Returns the string used in vertical tab summary. Overrides DrupalDataCollectorInterface::getPanelSummary
CacheDataCollector::getTitle public function Returns the datacollector title. Overrides DrupalDataCollectorInterface::getTitle
CacheDataCollector::registerCacheHit public function Registers a cache get on a specific cache bin.
CacheDataCollector::registerCacheMiss public function Registers a cache get on a specific cache bin.
CacheDataCollector::WEBPROFILER_CACHE_HIT constant
CacheDataCollector::WEBPROFILER_CACHE_MISS constant
CacheDataCollector::__construct public function
DrupalDataCollectorInterface::getData public function 8
DrupalDataCollectorInterface::getDrupalSettings public function 1
DrupalDataCollectorInterface::getLibraries public function Returns the libraries needed in detail panel. 2
DrupalDataCollectorInterface::hasPanel public function Returns true if this datacollector has a detail panel. 2
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.