| 1 |
<?php |
| 2 |
|
| 3 |
namespace Wikimedia\WRStats; |
| 4 |
|
| 5 |
use Wikimedia\ObjectCache\BagOStuff; |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
class BagOStuffStatsStore implements StatsStore { |
| 14 |
|
| 15 |
private $cache; |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
public function __construct( BagOStuff $cache ) { |
| 21 |
$this->cache = $cache; |
| 22 |
} |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 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, |
| 45 |
BagOStuff::WRITE_BACKGROUND |
| 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 |
} |