34 private $reboundDelay;
36 private $useFileCache;
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';
86 private $titleFactory;
104 $this->hookRunner =
new HookRunner( $hookContainer );
105 $this->titleFactory = $titleFactory;
106 $this->reboundDelay = $reboundDelay;
107 $this->useFileCache = $useFileCache;
108 $this->cdnMaxAge = $cdnMaxAge;
116 private function fieldHasFlag( $flags, $flag ) {
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 ) {
180 if ( $this->fieldHasFlag( $flags, self::PURGE_PRESEND ) ) {
181 DeferredUpdates::addUpdate( $update, DeferredUpdates::PRESEND );
187 $minFreshCacheMtime = $unless[self::UNLESS_CACHE_MTIME_AFTER] ??
null;
188 if ( !$minFreshCacheMtime || time() <= ( $minFreshCacheMtime + $this->cdnMaxAge ) ) {
190 foreach ( $pageIdentities as $pi ) {
193 $urls = array_merge( $urls, $this->
getUrls( $pi, $flags ) );
207 $title = $this->titleFactory->castFromPageReference( $page );
209 if ( !
$title->canExist() ) {
224 if ( !$this->fieldHasFlag( $flags, self::PURGE_URLS_LINKSUPDATE_ONLY ) ) {
225 $urls[] =
$title->getInternalURL(
'action=history' );
228 if (
$title->isUserJsConfigPage() ||
$title->isSiteJsConfigPage() ) {
229 $urls[] =
$title->getInternalURL(
'action=raw&ctype=text/javascript' );
230 } elseif (
$title->isUserJsonConfigPage() ||
$title->isSiteJsonConfigPage() ) {
231 $urls[] =
$title->getInternalURL(
'action=raw&ctype=application/json' );
232 } elseif (
$title->isUserCssConfigPage() ||
$title->isSiteCssConfigPage() ) {
233 $urls[] =
$title->getInternalURL(
'action=raw&ctype=text/css' );
239 $mode = $flags & self::PURGE_URLS_LINKSUPDATE_ONLY;
241 $this->hookRunner->onHtmlCacheUpdaterAppendUrls(
$title, $mode, $append );
242 $urls = array_merge( $urls, $append );
246 $this->hookRunner->onHtmlCacheUpdaterVaryUrls( $urls, $append );
247 $urls = array_merge( $urls, $append );
251 $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.
purgeUrls( $urls, $flags=self::PURGE_PRESEND, array $unless=[])
Purge the CDN for a URL or list of URLs.
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)
static newFromPages( $pages)
Interface for objects (potentially) representing an editable wiki page.