42 public const PURGE_NAIVE = 0;
48 public const PURGE_PRESEND = 1;
53 public const PURGE_REBOUND = 2;
63 public const PURGE_INTENT_TXROUND_REFLECTED = self::PURGE_PRESEND | self::PURGE_REBOUND;
73 public const PURGE_URLS_LINKSUPDATE_ONLY = 4;
81 public const UNLESS_CACHE_MTIME_AFTER =
'unless-timestamp-exceeds';
91 $useFileCache, $cdnMaxAge
93 $this->hookRunner =
new HookRunner( $hookContainer );
94 $this->reboundDelay = $reboundDelay;
95 $this->useFileCache = $useFileCache;
96 $this->cdnMaxAge = $cdnMaxAge;
105 return ( ( $flags & $flag ) === $flag );
116 public function purgeUrls( $urls, $flags = self::PURGE_PRESEND, array $unless = [] ) {
117 $minFreshCacheMtime = $unless[self::UNLESS_CACHE_MTIME_AFTER] ??
null;
118 if ( $minFreshCacheMtime && time() > ( $minFreshCacheMtime + $this->cdnMaxAge ) ) {
122 $urls = is_string( $urls ) ? [ $urls ] : $urls;
124 $reboundDelay = $this->
fieldHasFlag( $flags, self::PURGE_REBOUND )
125 ? $this->reboundDelay
128 $update =
new CdnCacheUpdate( $urls, [
'reboundDelay' => $reboundDelay ] );
129 if ( $this->
fieldHasFlag( $flags, self::PURGE_PRESEND ) ) {
130 DeferredUpdates::addUpdate( $update, DeferredUpdates::PRESEND );
147 public function purgeTitleUrls( $titles, $flags = self::PURGE_PRESEND, array $unless = [] ) {
148 $titles = $titles instanceof
Title ? [ $titles ] : $titles;
150 if ( $this->useFileCache ) {
152 if ( $this->
fieldHasFlag( $flags, self::PURGE_PRESEND ) ) {
153 DeferredUpdates::addUpdate( $update, DeferredUpdates::PRESEND );
159 $minFreshCacheMtime = $unless[self::UNLESS_CACHE_MTIME_AFTER] ??
null;
160 if ( !$minFreshCacheMtime || time() <= ( $minFreshCacheMtime + $this->cdnMaxAge ) ) {
162 foreach ( $titles as
$title ) {
164 $urls = array_merge( $urls, $this->
getUrls(
$title, $flags ) );
189 if ( !$this->
fieldHasFlag( $flags, self::PURGE_URLS_LINKSUPDATE_ONLY ) ) {
190 $urls[] =
$title->getInternalURL(
'action=history' );
193 if (
$title->isUserJsConfigPage() ) {
194 $urls[] =
$title->getInternalURL(
'action=raw&ctype=text/javascript' );
195 } elseif (
$title->isUserJsonConfigPage() ) {
196 $urls[] =
$title->getInternalURL(
'action=raw&ctype=application/json' );
197 } elseif (
$title->isUserCssConfigPage() ) {
198 $urls[] =
$title->getInternalURL(
'action=raw&ctype=text/css' );
204 $mode = $flags & self::PURGE_URLS_LINKSUPDATE_ONLY;
205 $this->hookRunner->onHtmlCacheUpdaterAppendUrls(
$title, $mode, $append );
206 $urls = array_merge( $urls, $append );
210 $this->hookRunner->onHtmlCacheUpdaterVaryUrls( $urls, $append );
211 $urls = array_merge( $urls, $append );
214 $this->hookRunner->onTitleSquidURLs(
$title, $urls );
Handles purging the appropriate CDN objects given a list of URLs or Title instances.
Class to invalidate the CDN and HTMLFileCache entries associated with URLs/titles.
int $useFileCache
Whether filesystem-based HTML output caching is enabled.
int $cdnMaxAge
Max seconds for CDN to served cached objects without revalidation.
getUrls(Title $title, int $flags=0)
Get a list of URLs to purge from the CDN cache when this page changes.
__construct(HookContainer $hookContainer, $reboundDelay, $useFileCache, $cdnMaxAge)
purgeUrls( $urls, $flags=self::PURGE_PRESEND, array $unless=[])
Purge the CDN for a URL or list of URLs.
purgeTitleUrls( $titles, $flags=self::PURGE_PRESEND, array $unless=[])
Purge the CDN/HTMLFileCache for a title or the titles yielded by an iterator.
fieldHasFlag( $flags, $flag)
int $reboundDelay
Seconds between initial and rebound purges; 0 if disabled.
static newFromTitles( $titles)
Represents a title within MediaWiki.