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 RuntimeException(
"Unable to create the localisation store " .
89 "directory \"{$this->directory}\"" );
93 if ( !empty( $this->readers[$code] ) ) {
94 $this->readers[$code]->close();
97 $this->writer = Writer::open( $this->
getFileName( $code ) );
98 $this->currentLang = $code;
102 $this->writer->close();
103 $this->writer =
null;
104 unset( $this->readers[$this->currentLang] );
105 $this->currentLang =
null;
108 public function set( $key, $value ) {
109 if ( $this->writer ===
null ) {
110 throw new LogicException( __CLASS__ .
': must call startWrite() before calling set()' );
112 $this->writer->set( $key, serialize( $value ) );
116 if ( strval( $code ) ===
'' || strpos( $code,
'/' ) !==
false ) {
117 throw new InvalidArgumentException( __METHOD__ .
": Invalid language \"$code\"" );
120 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.
Interface for the persistence layer of LocalisationCache.