You are here

class MemcacheStatsEvent in Memcache API and Integration 8.2

Memcache Stats Event

The memcache stats event stores all the attributes generated by the different types of memcache servers. Currently memcache_admin supports memcache and mcrouter.

Hierarchy

  • class \Drupal\memcache_admin\Event\MemcacheStatsEvent extends \Symfony\Component\EventDispatcher\Event

Expanded class hierarchy of MemcacheStatsEvent

3 files declare their use of MemcacheStatsEvent
McrouterStatsSubscriber.php in memcache_admin/src/EventSubscriber/McrouterStatsSubscriber.php
MemcacheServerStatsSubscriber.php in memcache_admin/src/EventSubscriber/MemcacheServerStatsSubscriber.php
MemcacheStatisticsController.php in memcache_admin/src/Controller/MemcacheStatisticsController.php

File

memcache_admin/src/Event/MemcacheStatsEvent.php, line 15

Namespace

Drupal\memcache_admin\Event
View source
class MemcacheStatsEvent extends Event {

  /**
   * Event used to build the memcache stats array.
   *
   * When the stats array is created, this event allows modules to inject extra
   * data to be contained within the array.
   */
  const BUILD_MEMCACHE_STATS = 'memcache_build_memcache_stats';

  /**
   * Event used to report out the memcache stats array.
   *
   * When the stats array is created, this event allows modules to inject extra
   * data to be contained within the array.
   */
  const REPORT_MEMCACHE_STATS = 'memcache_report_memcache_stats';

  /**
   * The Stats Array for which to create attributes.
   *
   * @var array
   */
  protected $rawStats;

  /**
   * The Stats Array for which to create attributes.
   *
   * @var array
   */
  protected $formattedStats = [];

  /**
   * The Stats Array for which to create attributes.
   *
   * @var array
   */
  protected $totals;

  /**
   * The Stats Array for which to create attributes.
   *
   * @var array
   */
  protected $report;

  /**
   * The Stats Array for which to create attributes.
   *
   * @var array
   */
  protected $servers;

  /**
   * Cache Bin To Retrieve
   * @var string $bin
   */
  protected $bin;
  protected $memcache;

  /**
   * MemcacheStatsEvent constructor.
   *
   * @param array $raw_stats
   *   The Stats Data.
   * @param string $bin
   *   The cache bin.
   *
   */
  public function __construct(DrupalMemcacheInterface $memcache, string $bin = 'default') {
    $this->memcache = $memcache;
    $this->rawStats = $memcache
      ->stats($bin, 'default', TRUE);
    $this->formattedStats = [];
    $this->bin = $bin;
  }

  /**
   * Get the Stats Array being created.
   *
   * @return array
   *   The Stats Object.
   */
  public function getRawStats() {
    return $this->rawStats;
  }

  /**
   * Gets the stats formatted from a MemcacheStatsInterface.
   * @param $server_type
   *
   * @return array|mixed
   */
  public function getFormattedStats($server_type) {
    if (isset($this->formattedStats[$server_type])) {
      return $this->formattedStats[$server_type];
    }
    return [];
  }

  /**
   * Returns the memcache connection.
   */
  public function getMemcache() {
    return $this->memcache;
  }

  /**
   * Returns the cache bin from this event.
   */
  public function getCacheBin() {
    return $this->bin;
  }

  /**
   * Sets the formatted stats array with relevant data.
   *
   * @param string $format
   * @param string $bin
   * @param string $server
   * @param \Drupal\memcache_admin\Stats\MemcacheStatsInterface $data
   */
  public function updateFormattedStats($format, $bin, $server, $data) {
    $this->formattedStats[$format][$bin][$server] = $data;
  }

  /**
   * Update the total column when multiple memcache servers exist.
   * @param $total
   */
  public function updateTotals($total) {
    $this->totals = $total;
  }

  /**
   * Return the total values from all memcache servers.
   * @return array
   */
  public function getTotals() {
    return $this->totals;
  }

  /**
   * Add a new server to the servers array.
   * @param string $server
   */
  public function updateServers($server) {
    $this->servers[] = $server;
  }

  /**
   * Retrieve all servers from the servers array.
   *
   * @return array
   */
  public function getServers() {
    return $this->servers;
  }

  /**
   * Update the full report from the event.
   * @param $report
   */
  public function updateReport($report) {
    $this->report = $report;
  }

  /**
   * Returns the stats report.
   * @return array
   */
  public function getReport() {
    return $this->report;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MemcacheStatsEvent::$bin protected property Cache Bin To Retrieve
MemcacheStatsEvent::$formattedStats protected property The Stats Array for which to create attributes.
MemcacheStatsEvent::$memcache protected property
MemcacheStatsEvent::$rawStats protected property The Stats Array for which to create attributes.
MemcacheStatsEvent::$report protected property The Stats Array for which to create attributes.
MemcacheStatsEvent::$servers protected property The Stats Array for which to create attributes.
MemcacheStatsEvent::$totals protected property The Stats Array for which to create attributes.
MemcacheStatsEvent::BUILD_MEMCACHE_STATS constant Event used to build the memcache stats array.
MemcacheStatsEvent::getCacheBin public function Returns the cache bin from this event.
MemcacheStatsEvent::getFormattedStats public function Gets the stats formatted from a MemcacheStatsInterface.
MemcacheStatsEvent::getMemcache public function Returns the memcache connection.
MemcacheStatsEvent::getRawStats public function Get the Stats Array being created.
MemcacheStatsEvent::getReport public function Returns the stats report.
MemcacheStatsEvent::getServers public function Retrieve all servers from the servers array.
MemcacheStatsEvent::getTotals public function Return the total values from all memcache servers.
MemcacheStatsEvent::REPORT_MEMCACHE_STATS constant Event used to report out the memcache stats array.
MemcacheStatsEvent::updateFormattedStats public function Sets the formatted stats array with relevant data.
MemcacheStatsEvent::updateReport public function Update the full report from the event.
MemcacheStatsEvent::updateServers public function Add a new server to the servers array.
MemcacheStatsEvent::updateTotals public function Update the total column when multiple memcache servers exist.
MemcacheStatsEvent::__construct public function MemcacheStatsEvent constructor.