MediaWiki master
LocalisationCacheBulkLoad.php
Go to the documentation of this file.
1<?php
29
35 private $fileCache = [];
36
43 private $mruLangs = [];
44
49 private $maxLoadedLangs = 10;
50
56 protected function readPHPFile( $fileName, $fileType ) {
57 $serialize = $fileType === 'core';
58 if ( !isset( $this->fileCache[$fileName][$fileType] ) ) {
59 $data = parent::readPHPFile( $fileName, $fileType );
60
61 if ( $serialize ) {
62 $encData = serialize( $data );
63 } else {
64 $encData = $data;
65 }
66
67 $this->fileCache[$fileName][$fileType] = $encData;
68
69 return $data;
70 } elseif ( $serialize ) {
71 return unserialize( $this->fileCache[$fileName][$fileType] );
72 } else {
73 return $this->fileCache[$fileName][$fileType];
74 }
75 }
76
82 public function getItem( $code, $key ) {
83 unset( $this->mruLangs[$code] );
84 $this->mruLangs[$code] = true;
85
86 return parent::getItem( $code, $key );
87 }
88
95 public function getSubitem( $code, $key, $subkey ) {
96 unset( $this->mruLangs[$code] );
97 $this->mruLangs[$code] = true;
98
99 return parent::getSubitem( $code, $key, $subkey );
100 }
101
105 public function recache( $code ) {
106 parent::recache( $code );
107 unset( $this->mruLangs[$code] );
108 $this->mruLangs[$code] = true;
109 $this->trimCache();
110 }
111
115 public function unload( $code ) {
116 unset( $this->mruLangs[$code] );
117 parent::unload( $code );
118 }
119
123 protected function trimCache() {
124 while ( count( $this->data ) > $this->maxLoadedLangs && count( $this->mruLangs ) ) {
125 $code = array_key_first( $this->mruLangs );
126 wfDebug( __METHOD__ . ": unloading $code" );
127 $this->unload( $code );
128 }
129 }
130
131}
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.