wiki.techinc.nl/includes/libs/WRStats/BagOStuffStatsStore.php
Ebrahim Byagowi fab78547ad Add namespace to the root classes of ObjectCache
And deprecated aliases for the the no namespaced classes.

ReplicatedBagOStuff that already is deprecated isn't moved.

Bug: T353458
Change-Id: Ie01962517e5b53e59b9721e9996d4f1ea95abb51
2024-07-10 00:14:54 +03:30

57 lines
1.1 KiB
PHP

<?php
namespace Wikimedia\WRStats;
use Wikimedia\ObjectCache\BagOStuff;
/**
* An adaptor allowing WRStats to store data in MediaWiki's BagOStuff
*
* @newable
* @since 1.39
*/
class BagOStuffStatsStore implements StatsStore {
/** @var BagOStuff */
private $cache;
/**
* @param BagOStuff $cache
*/
public function __construct( BagOStuff $cache ) {
$this->cache = $cache;
}
/**
* @inheritDoc
* @suppress PhanParamTooFewUnpack
*/
public function makeKey( $prefix, $internals, $entity ) {
if ( $entity->isGlobal() ) {
return $this->cache->makeGlobalKey(
...$prefix, ...$internals, ...$entity->getComponents() );
} else {
return $this->cache->makeKey(
...$prefix, ...$internals, ...$entity->getComponents() );
}
}
public function incr( array $values, $ttl ) {
foreach ( $values as $key => $value ) {
$this->cache->incrWithInit(
$key,
$ttl,
$value,
$value,
BagOStuff::WRITE_BACKGROUND
);
}
}
public function delete( array $keys ) {
$this->cache->deleteMulti( $keys, BagOStuff::WRITE_BACKGROUND );
}
public function query( array $keys ) {
return $this->cache->getMulti( $keys );
}
}