35 private $reboundDelay;
37 private $useFileCache;
45 public const PURGE_NAIVE = 0;
51 public const PURGE_PRESEND = 1;
56 public const PURGE_REBOUND = 2;
66 public const PURGE_INTENT_TXROUND_REFLECTED = self::PURGE_PRESEND | self::PURGE_REBOUND;
76 public const PURGE_URLS_LINKSUPDATE_ONLY = 4;
84 public const UNLESS_CACHE_MTIME_AFTER =
'unless-timestamp-exceeds';
87 private $titleFactory;
105 $this->hookRunner =
new HookRunner( $hookContainer );
106 $this->titleFactory = $titleFactory;
107 $this->reboundDelay = $reboundDelay;
108 $this->useFileCache = $useFileCache;
109 $this->cdnMaxAge = $cdnMaxAge;
117 private function fieldHasFlag( $flags, $flag ) {
118 return ( ( $flags & $flag ) === $flag );
129 public function purgeUrls( $urls, $flags = self::PURGE_PRESEND, array $unless = [] ) {
130 $minFreshCacheMtime = $unless[self::UNLESS_CACHE_MTIME_AFTER] ??
null;
131 if ( $minFreshCacheMtime && time() > ( $minFreshCacheMtime + $this->cdnMaxAge ) ) {
135 $urls = is_string( $urls ) ? [ $urls ] : $urls;
137 $reboundDelay = $this->fieldHasFlag( $flags, self::PURGE_REBOUND )
138 ? $this->reboundDelay
141 $update =
new CdnCacheUpdate( $urls, [
'reboundDelay' => $reboundDelay ] );
142 if ( $this->fieldHasFlag( $flags, self::PURGE_PRESEND ) ) {
161 public function purgeTitleUrls( $pages, $flags = self::PURGE_PRESEND, array $unless = [] ) {
162 $pages = is_iterable( $pages ) ? $pages : [ $pages ];
163 $pageIdentities = [];
165 foreach ( $pages as $page ) {
167 $title = $this->titleFactory->newFromPageReference( $page );
169 if (
$title->canExist() ) {
170 $pageIdentities[] =
$title;
174 if ( !$pageIdentities ) {
178 if ( $this->useFileCache ) {
180 if ( $this->fieldHasFlag( $flags, self::PURGE_PRESEND ) ) {
187 $minFreshCacheMtime = $unless[self::UNLESS_CACHE_MTIME_AFTER] ??
null;
188 if ( !$minFreshCacheMtime || time() <= ( $minFreshCacheMtime + $this->cdnMaxAge ) ) {
190 foreach ( $pageIdentities as $pi ) {
192 $urls = array_merge( $urls, $this->
getUrls( $pi, $flags ) );
206 $title = $this->titleFactory->newFromPageReference( $page );
208 if ( !
$title->canExist() ) {
223 if ( !$this->fieldHasFlag( $flags, self::PURGE_URLS_LINKSUPDATE_ONLY ) ) {
224 $urls[] =
$title->getInternalURL(
'action=history' );
227 if (
$title->isUserJsConfigPage() ||
$title->isSiteJsConfigPage() ) {
228 $urls[] =
$title->getInternalURL(
'action=raw&ctype=text/javascript' );
229 } elseif (
$title->isUserJsonConfigPage() ||
$title->isSiteJsonConfigPage() ) {
230 $urls[] =
$title->getInternalURL(
'action=raw&ctype=application/json' );
231 } elseif (
$title->isUserCssConfigPage() ||
$title->isSiteCssConfigPage() ) {
232 $urls[] =
$title->getInternalURL(
'action=raw&ctype=text/css' );
238 $mode = $flags & self::PURGE_URLS_LINKSUPDATE_ONLY;
239 $this->hookRunner->onHtmlCacheUpdaterAppendUrls(
$title, $mode, $append );
240 $urls = array_merge( $urls, $append );
244 $this->hookRunner->onHtmlCacheUpdaterVaryUrls( $urls, $append );
245 $urls = array_merge( $urls, $append );
248 $this->hookRunner->onTitleSquidURLs(
$title, $urls );
Handles purging the appropriate CDN objects given a list of URLs or Title instances.
static addUpdate(DeferrableUpdate $update, $stage=self::POSTSEND)
Add an update to the pending update queue for execution at the appropriate time.
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.