27use Psr\Log\LoggerAwareInterface;
28use Psr\Log\LoggerInterface;
29use Psr\Log\NullLogger;
53 private $resourceloader;
71 $this->resourceloader = $rl;
72 $this->logger =
$logger ?:
new NullLogger();
78 ->getMainWANObjectCache();
99 return $blobs[$module->
getName()];
117 $cache->makeGlobalKey( __CLASS__ )
120 foreach (
$modules as $name => $module ) {
121 $cacheKey = $this->makeCacheKey( $module,
$lang );
122 $cacheKeys[$name] = $cacheKey;
124 $checkKeys[$cacheKey][] =
$cache->makeKey( __CLASS__, $name );
127 $result =
$cache->getMulti( array_values( $cacheKeys ), $curTTLs, $checkKeys );
130 foreach (
$modules as $name => $module ) {
131 $key = $cacheKeys[$name];
132 if ( !isset( $result[$key] ) || $curTTLs[$key] ===
null || $curTTLs[$key] < 0 ) {
136 $blobs[$name] = $result[$key];
148 private function makeCacheKey(
Module $module,
$lang ) {
149 $messages = array_values( array_unique( $module->
getMessages() ) );
151 return $this->wanCache->makeKey( __CLASS__, $module->
getName(),
$lang,
152 md5( json_encode( $messages ) )
164 $blob = $this->generateMessageBlob( $module,
$lang );
168 $cache::TTL_WEEK + mt_rand( 0, $cache::TTL_DAY ),
181 $moduleNames = $this->resourceloader->getModulesByMessage( $key );
182 foreach ( $moduleNames as $moduleName ) {
184 $this->wanCache->touchCheckKey( $this->wanCache->makeKey( __CLASS__, $moduleName ) );
192 self::clearGlobalCacheEntry( $this->wanCache );
210 $cache->touchCheckKey(
$cache->makeGlobalKey( __CLASS__ ), $cache::HOLDOFF_TTL_NONE );
221 if ( !$message->exists() ) {
222 $this->logger->warning(
'Failed to find {messageKey} ({lang})', [
223 'messageKey' => $key,
228 $value = $message->plain();
240 private function generateMessageBlob(
Module $module,
$lang ) {
243 $value = $this->fetchMessage( $key,
$lang );
246 if ( $value !==
null ) {
247 $messages[$key] = $value;
251 $json = FormatJson::encode( (
object)$messages,
false, FormatJson::UTF8_OK );
253 if ( $json ===
false ) {
254 $this->logger->warning(
'Failed to encode message blob for {module} ({lang})', [
255 'module' => $module->
getName(),
266class_alias( MessageBlobStore::class,
'MessageBlobStore' );
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Multi-datacenter aware caching interface.
set( $key, $value, $ttl=self::TTL_INDEFINITE, array $opts=[])
Set the value of a key in cache.
if(!isset( $args[0])) $lang