MediaWiki REL1_39
LocalisationCacheBulkLoad.php
Go to the documentation of this file.
1<?php
29
34 private $fileCache = [];
35
41 private $mruLangs = [];
42
46 private $maxLoadedLangs = 10;
47
53 protected function readPHPFile( $fileName, $fileType ) {
54 $serialize = $fileType === 'core';
55 if ( !isset( $this->fileCache[$fileName][$fileType] ) ) {
56 $data = parent::readPHPFile( $fileName, $fileType );
57
58 if ( $serialize ) {
59 $encData = serialize( $data );
60 } else {
61 $encData = $data;
62 }
63
64 $this->fileCache[$fileName][$fileType] = $encData;
65
66 return $data;
67 } elseif ( $serialize ) {
68 return unserialize( $this->fileCache[$fileName][$fileType] );
69 } else {
70 return $this->fileCache[$fileName][$fileType];
71 }
72 }
73
79 public function getItem( $code, $key ) {
80 unset( $this->mruLangs[$code] );
81 $this->mruLangs[$code] = true;
82
83 return parent::getItem( $code, $key );
84 }
85
92 public function getSubitem( $code, $key, $subkey ) {
93 unset( $this->mruLangs[$code] );
94 $this->mruLangs[$code] = true;
95
96 return parent::getSubitem( $code, $key, $subkey );
97 }
98
102 public function recache( $code ) {
103 parent::recache( $code );
104 unset( $this->mruLangs[$code] );
105 $this->mruLangs[$code] = true;
106 $this->trimCache();
107 }
108
112 public function unload( $code ) {
113 unset( $this->mruLangs[$code] );
114 parent::unload( $code );
115 }
116
120 protected function trimCache() {
121 while ( count( $this->data ) > $this->maxLoadedLangs && count( $this->mruLangs ) ) {
122 reset( $this->mruLangs );
123 $code = key( $this->mruLangs );
124 wfDebug( __METHOD__ . ": unloading $code" );
125 $this->unload( $code );
126 }
127 }
128
129}
serialize()
unserialize( $serialized)
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.