X-Git-Url: https://scripts.mit.edu/gitweb/autoinstallsdev/mediawiki.git/blobdiff_plain/19e297c21b10b1b8a3acad5e73fc71dcb35db44a..6932310fd58ebef145fa01eb76edf7150284d8ea:/includes/cache/localisation/LocalisationCacheBulkLoad.php diff --git a/includes/cache/localisation/LocalisationCacheBulkLoad.php b/includes/cache/localisation/LocalisationCacheBulkLoad.php new file mode 100644 index 00000000..30c7d375 --- /dev/null +++ b/includes/cache/localisation/LocalisationCacheBulkLoad.php @@ -0,0 +1,126 @@ +data + */ + private $maxLoadedLangs = 10; + + /** + * @param string $fileName + * @param string $fileType + * @return array|mixed + */ + protected function readPHPFile( $fileName, $fileType ) { + $serialize = $fileType === 'core'; + if ( !isset( $this->fileCache[$fileName][$fileType] ) ) { + $data = parent::readPHPFile( $fileName, $fileType ); + + if ( $serialize ) { + $encData = serialize( $data ); + } else { + $encData = $data; + } + + $this->fileCache[$fileName][$fileType] = $encData; + + return $data; + } elseif ( $serialize ) { + return unserialize( $this->fileCache[$fileName][$fileType] ); + } else { + return $this->fileCache[$fileName][$fileType]; + } + } + + /** + * @param string $code + * @param string $key + * @return mixed + */ + public function getItem( $code, $key ) { + unset( $this->mruLangs[$code] ); + $this->mruLangs[$code] = true; + + return parent::getItem( $code, $key ); + } + + /** + * @param string $code + * @param string $key + * @param string $subkey + * @return mixed + */ + public function getSubitem( $code, $key, $subkey ) { + unset( $this->mruLangs[$code] ); + $this->mruLangs[$code] = true; + + return parent::getSubitem( $code, $key, $subkey ); + } + + /** + * @param string $code + */ + public function recache( $code ) { + parent::recache( $code ); + unset( $this->mruLangs[$code] ); + $this->mruLangs[$code] = true; + $this->trimCache(); + } + + /** + * @param string $code + */ + public function unload( $code ) { + unset( $this->mruLangs[$code] ); + parent::unload( $code ); + } + + /** + * Unload cached languages until there are less than $this->maxLoadedLangs + */ + protected function trimCache() { + while ( count( $this->data ) > $this->maxLoadedLangs && count( $this->mruLangs ) ) { + reset( $this->mruLangs ); + $code = key( $this->mruLangs ); + wfDebug( __METHOD__ . ": unloading $code\n" ); + $this->unload( $code ); + } + } + +}