MediaWiki  master
BagOStuffStatsStore.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Wikimedia\WRStats;
4 
5 use BagOStuff;
6 
13 class BagOStuffStatsStore implements StatsStore {
15  private $cache;
16 
20  public function __construct( BagOStuff $cache ) {
21  $this->cache = $cache;
22  }
23 
28  public function makeKey( $prefix, $internals, $entity ) {
29  if ( $entity->isGlobal() ) {
30  return $this->cache->makeGlobalKey(
31  ...$prefix, ...$internals, ...$entity->getComponents() );
32  } else {
33  return $this->cache->makeKey(
34  ...$prefix, ...$internals, ...$entity->getComponents() );
35  }
36  }
37 
38  public function incr( array $values, $ttl ) {
39  foreach ( $values as $key => $value ) {
40  $this->cache->incrWithInit(
41  $key,
42  $ttl,
43  $value,
44  $value,
46  );
47  }
48  }
49 
50  public function delete( array $keys ) {
51  $this->cache->deleteMulti( $keys, BagOStuff::WRITE_BACKGROUND );
52  }
53 
54  public function query( array $keys ) {
55  return $this->cache->getMulti( $keys );
56  }
57 }
Class representing a cache/ephemeral data store.
Definition: BagOStuff.php:85
const WRITE_BACKGROUND
If supported, do not block on write operation completion; instead, treat writes as succesful based on...
Definition: BagOStuff.php:128
An adaptor allowing WRStats to store data in MediaWiki's BagOStuff.
makeKey( $prefix, $internals, $entity)
Construct a string key from its components.The prefix components. The internal components....
incr(array $values, $ttl)
Perform a batch of increment operations.
query(array $keys)
Perform a batch of fetch operations.
The narrow interface WRStats needs into a memcached-like key-value store.
Definition: StatsStore.php:10