44 public const PURGE_NAIVE = 0;
50 public const PURGE_PRESEND = 1;
55 public const PURGE_REBOUND = 2;
65 public const PURGE_INTENT_TXROUND_REFLECTED = self::PURGE_PRESEND | self::PURGE_REBOUND;
75 public const PURGE_URLS_LINKSUPDATE_ONLY = 4;
83 public const UNLESS_CACHE_MTIME_AFTER =
'unless-timestamp-exceeds';
104 $this->hookRunner =
new HookRunner( $hookContainer );
105 $this->titleFactory = $titleFactory;
106 $this->reboundDelay = $reboundDelay;
107 $this->useFileCache = $useFileCache;
108 $this->cdnMaxAge = $cdnMaxAge;
117 return ( ( $flags & $flag ) === $flag );
128 public function purgeUrls( $urls, $flags = self::PURGE_PRESEND, array $unless = [] ) {
129 $minFreshCacheMtime = $unless[self::UNLESS_CACHE_MTIME_AFTER] ??
null;
130 if ( $minFreshCacheMtime && time() > ( $minFreshCacheMtime + $this->cdnMaxAge ) ) {
134 $urls = is_string( $urls ) ? [ $urls ] : $urls;
136 $reboundDelay = $this->
fieldHasFlag( $flags, self::PURGE_REBOUND )
137 ? $this->reboundDelay
140 $update =
new CdnCacheUpdate( $urls, [
'reboundDelay' => $reboundDelay ] );
141 if ( $this->
fieldHasFlag( $flags, self::PURGE_PRESEND ) ) {
142 DeferredUpdates::addUpdate( $update, DeferredUpdates::PRESEND );
160 public function purgeTitleUrls( $pages, $flags = self::PURGE_PRESEND, array $unless = [] ) {
161 $pages = is_iterable( $pages ) ? $pages : [ $pages ];
162 $pageIdentities = [];
164 foreach ( $pages as $page ) {
166 $title = $this->titleFactory->castFromPageReference( $page );
168 if (
$title->canExist() ) {
169 $pageIdentities[] =
$title;
173 if ( !$pageIdentities ) {
177 if ( $this->useFileCache ) {
179 if ( $this->
fieldHasFlag( $flags, self::PURGE_PRESEND ) ) {
180 DeferredUpdates::addUpdate( $update, DeferredUpdates::PRESEND );
186 $minFreshCacheMtime = $unless[self::UNLESS_CACHE_MTIME_AFTER] ??
null;
187 if ( !$minFreshCacheMtime || time() <= ( $minFreshCacheMtime + $this->cdnMaxAge ) ) {
189 foreach ( $pageIdentities as $pi ) {
191 $urls = array_merge( $urls, $this->
getUrls( $pi, $flags ) );
205 $title = $this->titleFactory->castFromPageReference( $page );
207 if ( !
$title->canExist() ) {
222 if ( !$this->fieldHasFlag( $flags, self::PURGE_URLS_LINKSUPDATE_ONLY ) ) {
223 $urls[] =
$title->getInternalURL(
'action=history' );
226 if (
$title->isUserJsConfigPage() ||
$title->isSiteJsConfigPage() ) {
227 $urls[] =
$title->getInternalURL(
'action=raw&ctype=text/javascript' );
228 } elseif (
$title->isUserJsonConfigPage() ||
$title->isSiteJsonConfigPage() ) {
229 $urls[] =
$title->getInternalURL(
'action=raw&ctype=application/json' );
230 } elseif (
$title->isUserCssConfigPage() ||
$title->isSiteCssConfigPage() ) {
231 $urls[] =
$title->getInternalURL(
'action=raw&ctype=text/css' );
237 $mode = $flags & self::PURGE_URLS_LINKSUPDATE_ONLY;
238 $this->hookRunner->onHtmlCacheUpdaterAppendUrls(
$title, $mode, $append );
239 $urls = array_merge( $urls, $append );
243 $this->hookRunner->onHtmlCacheUpdaterVaryUrls( $urls, $append );
244 $urls = array_merge( $urls, $append );
247 $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.
purgeUrls( $urls, $flags=self::PURGE_PRESEND, array $unless=[])
Purge the CDN for a URL or list of URLs.
fieldHasFlag( $flags, $flag)
int $reboundDelay
Seconds between initial and rebound purges; 0 if disabled.
getUrls(PageReference $page, int $flags=0)
Get a list of URLs to purge from the CDN cache when this page changes.
purgeTitleUrls( $pages, $flags=self::PURGE_PRESEND, array $unless=[])
Purge the CDN/HTMLFileCache for a title or the titles yielded by an iterator.
__construct(HookContainer $hookContainer, TitleFactory $titleFactory, $reboundDelay, $useFileCache, $cdnMaxAge)
TitleFactory $titleFactory
static newFromPages( $pages)
Interface for objects (potentially) representing an editable wiki page.