49 $this->directory = $conf[
'directory'];
52 public function get( $code, $key ) {
53 if ( !isset( $this->readers[$code] ) ) {
56 $this->readers[$code] =
false;
57 if ( file_exists( $fileName ) ) {
59 $this->readers[$code] = Reader::open( $fileName );
60 }
catch ( Exception $e ) {
61 wfDebug( __METHOD__ .
": unable to open cdb file for reading\n" );
66 if ( !$this->readers[$code] ) {
71 $value = $this->readers[$code]->get( $key );
72 }
catch ( Exception $e ) {
73 wfDebug( __METHOD__ .
": \Cdb\Exception caught, error message was "
74 . $e->getMessage() .
"\n" );
76 if ( $value ===
false ) {
85 if ( !file_exists( $this->directory ) && !
wfMkdirParents( $this->directory,
null, __METHOD__ ) ) {
86 throw new MWException(
"Unable to create the localisation store " .
87 "directory \"{$this->directory}\"" );
91 if ( !empty( $this->readers[$code] ) ) {
92 $this->readers[$code]->close();
96 $this->writer = Writer::open( $this->
getFileName( $code ) );
97 }
catch ( Exception $e ) {
100 $this->currentLang = $code;
106 $this->writer->close();
107 }
catch ( Exception $e ) {
110 $this->writer =
null;
111 unset( $this->readers[$this->currentLang] );
112 $this->currentLang =
null;
115 public function set( $key, $value ) {
116 if ( is_null( $this->writer ) ) {
117 throw new MWException( __CLASS__ .
': must call startWrite() before calling set()' );
120 $this->writer->set( $key,
serialize( $value ) );
121 }
catch ( Exception $e ) {
127 if ( strval( $code ) ===
'' || strpos( $code,
'/' ) !==
false ) {
128 throw new MWException( __METHOD__ .
": Invalid language \"$code\"" );
131 return "{$this->directory}/l10n_cache-$code.cdb";
unserialize( $serialized)
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.
string $currentLang
Current language code.
startWrite( $code)
Start a write transaction.
Reader[] false[] $readers
string $directory
Cache directory.
finishWrite()
Finish a write transaction.
Interface for the persistence layer of LocalisationCache.