6use Cdb\Exception as CdbException;
37 $this->directory = $conf[
'directory'];
41 public function get( $code, $key ) {
42 if ( !isset( $this->readers[$code] ) ) {
45 $this->readers[$code] =
false;
46 if ( is_file( $fileName ) ) {
48 $this->readers[$code] = Reader::open( $fileName );
49 }
catch ( CdbException ) {
50 wfDebug( __METHOD__ .
": unable to open cdb file for reading" );
55 if ( !$this->readers[$code] ) {
60 $value = $this->readers[$code]->get( $key );
61 }
catch ( CdbException $e ) {
62 wfDebug( __METHOD__ .
": \Cdb\Exception caught, error message was "
65 if ( $value ===
false ) {
69 return unserialize( $value );
75 if ( !is_dir( $this->directory ) && !
wfMkdirParents( $this->directory,
null, __METHOD__ ) ) {
76 throw new RuntimeException(
"Unable to create the localisation store " .
77 "directory \"{$this->directory}\"" );
81 if ( !empty( $this->readers[$code] ) ) {
82 $this->readers[$code]->close();
85 $this->writer = Writer::open( $this->
getFileName( $code ) );
86 $this->currentLang = $code;
90 $this->writer->close();
92 unset( $this->readers[$this->currentLang] );
93 $this->currentLang =
null;
97 public function set( $key, $value ) {
98 if ( $this->writer ===
null ) {
99 throw new LogicException( __CLASS__ .
': must call startWrite() before calling set()' );
101 $this->writer->set( $key, serialize( $value ) );
109 if ( strval( $code ) ===
'' || str_contains( $code,
'/' ) ) {
110 throw new InvalidArgumentException( __METHOD__ .
": Invalid language \"$code\"" );
113 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 cache write transaction.
finishWrite()
Finish a cache write transaction.
__construct(array $conf=[])
Interface for the persistence layer of LocalisationCache.