MediaWiki master
LocalisationCacheBulkLoad.php
Go to the documentation of this file.
1<?php
7namespace MediaWiki\Language;
8
17
23 private $fileCache = [];
24
31 private $mruLangs = [];
32
37 private $maxLoadedLangs = 10;
38
44 protected function readPHPFile( $fileName, $fileType ) {
45 $serialize = $fileType === 'core';
46 if ( !isset( $this->fileCache[$fileName][$fileType] ) ) {
47 $data = parent::readPHPFile( $fileName, $fileType );
48
49 if ( $serialize ) {
50 $encData = serialize( $data );
51 } else {
52 $encData = $data;
53 }
54
55 $this->fileCache[$fileName][$fileType] = $encData;
56
57 return $data;
58 } elseif ( $serialize ) {
59 return unserialize( $this->fileCache[$fileName][$fileType] );
60 } else {
61 return $this->fileCache[$fileName][$fileType];
62 }
63 }
64
70 public function getItem( $code, $key ) {
71 unset( $this->mruLangs[$code] );
72 $this->mruLangs[$code] = true;
73
74 return parent::getItem( $code, $key );
75 }
76
83 public function getSubitem( $code, $key, $subkey ) {
84 unset( $this->mruLangs[$code] );
85 $this->mruLangs[$code] = true;
86
87 return parent::getSubitem( $code, $key, $subkey );
88 }
89
93 public function recache( $code ) {
94 parent::recache( $code );
95 unset( $this->mruLangs[$code] );
96 $this->mruLangs[$code] = true;
97 $this->trimCache();
98 }
99
103 public function unload( $code ) {
104 unset( $this->mruLangs[$code] );
105 parent::unload( $code );
106 }
107
111 protected function trimCache() {
112 while ( count( $this->data ) > $this->maxLoadedLangs && count( $this->mruLangs ) ) {
113 $code = array_key_first( $this->mruLangs );
114 wfDebug( __METHOD__ . ": unloading $code" );
115 $this->unload( $code );
116 }
117 }
118
119}
120
122class_alias( LocalisationCacheBulkLoad::class, 'LocalisationCacheBulkLoad' );
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
LocalisationCache optimised for loading many languages at once.
trimCache()
Unload cached languages until there are less than $this->maxLoadedLangs.
Caching for the contents of localisation files.
array< string, array > $data
The cache data.