20use Cdb\Exception as CdbException;
51 $this->directory = $conf[
'directory'];
54 public function get( $code, $key ) {
55 if ( !isset( $this->readers[$code] ) ) {
58 $this->readers[$code] =
false;
59 if ( is_file( $fileName ) ) {
61 $this->readers[$code] = Reader::open( $fileName );
62 }
catch ( CdbException $e ) {
63 wfDebug( __METHOD__ .
": unable to open cdb file for reading" );
68 if ( !$this->readers[$code] ) {
73 $value = $this->readers[$code]->get( $key );
74 }
catch ( CdbException $e ) {
75 wfDebug( __METHOD__ .
": \Cdb\Exception caught, error message was "
78 if ( $value ===
false ) {
82 return unserialize( $value );
87 if ( !is_dir( $this->directory ) && !
wfMkdirParents( $this->directory,
null, __METHOD__ ) ) {
88 throw new MWException(
"Unable to create the localisation store " .
89 "directory \"{$this->directory}\"" );
93 if ( !empty( $this->readers[$code] ) ) {
94 $this->readers[$code]->close();
98 $this->writer = Writer::open( $this->
getFileName( $code ) );
99 }
catch ( CdbException $e ) {
102 $this->currentLang = $code;
108 $this->writer->close();
109 }
catch ( CdbException $e ) {
112 $this->writer =
null;
113 unset( $this->readers[$this->currentLang] );
114 $this->currentLang =
null;
117 public function set( $key, $value ) {
118 if ( $this->writer ===
null ) {
119 throw new MWException( __CLASS__ .
': must call startWrite() before calling set()' );
122 $this->writer->set( $key, serialize( $value ) );
123 }
catch ( CdbException $e ) {
129 if ( strval( $code ) ===
'' || strpos( $code,
'/' ) !==
false ) {
130 throw new MWException( __METHOD__ .
": Invalid language \"$code\"" );
133 return "{$this->directory}/l10n_cache-$code.cdb";
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfMkdirParents( $dir, $mode=null, $caller=null)
Make directory, and make all parent directories if they don't exist.
LCStore implementation which stores data as a collection of CDB files.
startWrite( $code)
Start a write transaction.
finishWrite()
Finish a write transaction.
Interface for the persistence layer of LocalisationCache.