MediaWiki master
ArrayStatsStore.php
Go to the documentation of this file.
1<?php
2
4
8class ArrayStatsStore implements StatsStore {
13 private $data = [];
14
16 public function makeKey( $prefix, $internals, $entity ) {
17 $globality = $entity->isGlobal() ? 'global' : 'local';
18 return implode( ':',
19 [ $globality, ...$prefix, ...$internals, ...$entity->getComponents() ]
20 );
21 }
22
24 public function incr( array $values, $ttl ) {
25 foreach ( $values as $key => $value ) {
26 if ( !isset( $this->data[$key] ) ) {
27 $this->data[$key] = [ 0, $ttl ];
28 }
29 $this->data[$key][0] += $value;
30 }
31 }
32
33 public function delete( array $keys ) {
34 foreach ( $keys as $key ) {
35 unset( $this->data[$key] );
36 }
37 }
38
40 public function query( array $keys ) {
41 $values = [];
42 foreach ( $keys as $key ) {
43 if ( isset( $this->data[$key] ) ) {
44 $values[$key] = $this->data[$key][0];
45 }
46 }
47 return $values;
48 }
49
53 public function getData() {
54 return $this->data;
55 }
56}
makeKey( $prefix, $internals, $entity)
Construct a string key from its components.string
query(array $keys)
Perform a batch of fetch operations.int[] Integers
incr(array $values, $ttl)
Perform a batch of increment operations.
Narrow interface for WRStatsFactory to a memcached-like key-value store.