46 $this->server = $params[
'server'] ?? [];
49 public function get(
$code, $key ) {
50 if ( $this->server || $this->writesDone ) {
59 $value = $db->selectField(
62 [
'lc_lang' =>
$code,
'lc_key' => $key ],
66 return ( $value !==
false ) ?
unserialize( $db->decodeBlob( $value ) ) :
null;
70 if ( $this->readOnly ) {
73 throw new MWException( __METHOD__ .
": Invalid language \"$code\"" );
84 if ( $this->readOnly ) {
86 } elseif ( $this->code ===
null ) {
87 throw new MWException( __CLASS__ .
': must call startWrite() before finishWrite()' );
90 $trxProfiler = Profiler::instance()->getTransactionProfiler();
91 $oldSilenced = $trxProfiler->setSilenced(
true );
96 $dbw->
delete(
'l10n_cache', [
'lc_lang' => $this->code ], __METHOD__ );
97 foreach ( array_chunk( $this->batch, 500 ) as $rows ) {
98 $dbw->
insert(
'l10n_cache', $rows, __METHOD__ );
100 $this->writesDone =
true;
103 $this->readOnly =
true;
110 $trxProfiler->setSilenced( $oldSilenced );
117 public function set( $key, $value ) {
118 if ( $this->readOnly ) {
120 } elseif ( $this->code ===
null ) {
121 throw new MWException( __CLASS__ .
': must call startWrite() before set()' );
138 if ( $this->server ) {
139 $this->dbw = Database::factory( $this->server[
'type'], $this->server );
141 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.