24use Wikimedia\ScopedCallback;
43 private $writesDone =
false;
45 private $readOnly =
false;
48 $this->server = $params[
'server'] ?? [];
51 public function get( $code, $key ) {
52 if ( $this->server || $this->writesDone ) {
56 $db = $this->getWriteConnection();
61 $value = $db->selectField(
64 [
'lc_lang' => $code,
'lc_key' => $key ],
68 return ( $value !==
false ) ?
unserialize( $db->decodeBlob( $value ) ) :
null;
72 if ( $this->readOnly ) {
75 throw new MWException( __METHOD__ .
": Invalid language \"$code\"" );
78 $dbw = $this->getWriteConnection();
86 if ( $this->readOnly ) {
88 } elseif ( $this->code ===
null ) {
89 throw new MWException( __CLASS__ .
': must call startWrite() before finishWrite()' );
92 $scope = Profiler::instance()->getTransactionProfiler()->silenceForScope();
93 $dbw = $this->getWriteConnection();
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;
109 ScopedCallback::consume( $scope );
115 public function set( $key, $value ) {
116 if ( $this->readOnly ) {
118 } elseif ( $this->code ===
null ) {
119 throw new MWException( __CLASS__ .
': must call startWrite() before set()' );
122 $dbw = $this->getWriteConnection();
125 'lc_lang' => $this->code,
134 private function getWriteConnection() {
136 if ( $this->server ) {
137 $this->dbw = Database::factory( $this->server[
'type'], $this->server );
139 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.
finishWrite()
Finish a write transaction.
startWrite( $code)
Start a write transaction.
Interface for the persistence layer of LocalisationCache.