27use Psr\Log\LoggerAwareInterface;
28use Psr\Log\LoggerInterface;
29use Psr\Log\NullLogger;
44 private $resourceloader;
62 $this->resourceloader = $rl;
63 $this->logger =
$logger ?:
new NullLogger();
69 ->getMainWANObjectCache();
90 return $blobs[$module->
getName()];
106 self::makeGlobalPurgeKey( $this->wanCache )
109 foreach (
$modules as $name => $module ) {
110 $cacheKey = $this->makeBlobCacheKey( $name,
$lang, $module );
111 $cacheKeys[$name] = $cacheKey;
112 $checkKeys[$cacheKey][] = $this->makeModulePurgeKey( $name );
115 $result = $this->wanCache->getMulti( array_values( $cacheKeys ), $curTTLs, $checkKeys );
118 foreach (
$modules as $name => $module ) {
119 $key = $cacheKeys[$name];
120 if ( !isset( $result[$key] ) || $curTTLs[$key] ===
null || $curTTLs[$key] < 0 ) {
124 $blobs[$name] = $result[$key];
136 private static function makeGlobalPurgeKey(
WANObjectCache $cache ) {
137 return $cache->
makeGlobalKey(
'resourceloader-messageblob' );
146 private function makeModulePurgeKey( $name ) {
147 return $this->wanCache->makeKey(
'resourceloader-messageblob', $name );
156 private function makeBlobCacheKey( $name,
$lang, Module $module ) {
157 $messages = array_values( array_unique( $module->getMessages() ) );
159 return $this->wanCache->makeKey(
'resourceloader-messageblob',
162 md5( json_encode( $messages ) )
174 $blob = $this->generateMessageBlob( $module,
$lang );
178 $cache::TTL_WEEK + mt_rand( 0, $cache::TTL_DAY ),
191 $moduleNames = $this->resourceloader->getModulesByMessage( $key );
192 foreach ( $moduleNames as $moduleName ) {
195 $this->wanCache->touchCheckKey( $this->makeModulePurgeKey( $moduleName ) );
205 self::clearGlobalCacheEntry( $this->wanCache );
223 $cache->
touchCheckKey( self::makeGlobalPurgeKey( $cache ), $cache::HOLDOFF_TTL_NONE );
234 if ( !$message->exists() ) {
235 $this->logger->warning(
'Failed to find {messageKey} ({lang})', [
236 'messageKey' => $key,
241 $value = $message->plain();
253 private function generateMessageBlob(
Module $module,
$lang ) {
256 $value = $this->fetchMessage( $key,
$lang );
259 if ( $value !==
null ) {
260 $messages[$key] = $value;
264 $json = FormatJson::encode( (
object)$messages,
false, FormatJson::UTF8_OK );
266 if ( $json ===
false ) {
267 $this->logger->warning(
'Failed to encode message blob for {module} ({lang})', [
268 'module' => $module->
getName(),
279class_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.
makeGlobalKey( $collection,... $components)
Make a cache key for the global keyspace and given components.
touchCheckKey( $key, $holdoff=self::HOLDOFF_TTL)
Increase the last-purge timestamp of a "check" key in all datacenters.
set( $key, $value, $ttl=self::TTL_INDEFINITE, array $opts=[])
Set the value of a key in cache.
if(!isset( $args[0])) $lang