24use Wikimedia\ScopedCallback;
47 $this->server = $params[
'server'] ?? [];
50 public function get(
$code, $key ) {
51 if ( $this->server || $this->writesDone ) {
60 $value = $db->selectField(
63 [
'lc_lang' =>
$code,
'lc_key' => $key ],
67 return ( $value !==
false ) ?
unserialize( $db->decodeBlob( $value ) ) :
null;
71 if ( $this->readOnly ) {
74 throw new MWException( __METHOD__ .
": Invalid language \"$code\"" );
85 if ( $this->readOnly ) {
87 } elseif ( $this->code ===
null ) {
88 throw new MWException( __CLASS__ .
': must call startWrite() before finishWrite()' );
91 $scope = Profiler::instance()->getTransactionProfiler()->silenceForScope();
95 $dbw->
delete(
'l10n_cache', [
'lc_lang' => $this->code ], __METHOD__ );
96 foreach ( array_chunk( $this->batch, 500 ) as $rows ) {
97 $dbw->
insert(
'l10n_cache', $rows, __METHOD__ );
99 $this->writesDone =
true;
102 $this->readOnly =
true;
108 ScopedCallback::consume( $scope );
114 public function set( $key, $value ) {
115 if ( $this->readOnly ) {
117 } elseif ( $this->code ===
null ) {
118 throw new MWException( __CLASS__ .
': must call startWrite() before set()' );
135 if ( $this->server ) {
136 $this->dbw = Database::factory( $this->server[
'type'], $this->server );
138 throw new MWException( __CLASS__ .
': failed to obtain a DB connection' );
unserialize( $serialized)
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
LCStore implementation which uses the standard DB functions to store data.
array $server
Server configuration map.
bool $readOnly
Whether the DB is read-only or otherwise unavailable for writes.
finishWrite()
Finish a write transaction.
startWrite( $code)
Start a write transaction.
string $code
Language code.
array $batch
Rows buffered for insertion.
bool $writesDone
Whether a batch of writes were recently written.
Interface for the persistence layer of LocalisationCache.