Cache warmup of pages located in XML sitemaps 

Extension key

warming

Package name

eliashaeussler/typo3-warming

Version

0.5

Language

en

Author

Elias Häußler & contributors

License

This extension documentation is published under the CC BY-NC-SA 4.0 (Creative Commons) license.


An extension for TYPO3 CMS that warms up Frontend caches based on an XML sitemap. Cache warmup can be triggered via TYPO3 backend or using a console command. It supports multiple languages and custom crawler implementations.


Table of Contents

Introduction 

What does it do? 

The extension provides a service to warm up Frontend caches based on an XML sitemap. Cache warmup can be triggered in various ways:

It supports multiple languages and custom crawler implementations. Under the hood, the extension makes use of the eliashaeussler/cache-warmup library which provides the core cache warmup implementation.

Features 

Support 

There are several ways to get support for this extension:

License 

This extension is licensed under GNU General Public License 2.0 (or later).

Installation 

Requirements 

  • PHP 7.4 - 8.2
  • TYPO3 10.4 LTS - 11.5 LTS

Installation 

Require the extension via Composer (recommended):

composer require eliashaeussler/typo3-warming
Copied!

Or download it from the TYPO3 extension repository.

Version matrix 

Extension versions TYPO3 versions PHP versions
since 0.5.5 10.4 LTS - 11.5 LTS 7.4 - 8.3
0.5.0 - 0.5.4 10.4 LTS - 11.5 LTS 7.4 - 8.2
0.3.14 - 0.4.8 10.4 LTS - 11.5 LTS 7.1 - 8.1
0.2.4 - 0.3.13 10.4 LTS - 11.5 LTS 7.1 - 8.0
0.2.0 - 0.2.3 10.4 LTS - 11.2 7.1 - 8.0
0.1.x 10.4 LTS - 11.1 7.1 - 8.0

Configuration 

The extension can be configured in many ways. Especially the behavior during the cache warmup can be configured extensively. For example, it is possible to limit the maximum number of crawled pages or even use your own crawler implementations.

Learn what configuration options are available on the following pages:

Extension configuration 

The extension currently provides the following configuration options:

limit

limit
type

integer

Default

250

Allows to limit the amount of crawled pages in one iteration.

crawler

crawler
type

string (FQCN)

Default

eliashaeussler-typo3warming-crawler-concurrentuseragentcrawler

Default crawler to be used for crawling the requested pages.

crawlerOptions

crawlerOptions
type

string (JSON)

JSON-encoded string of custom crawler options for the default crawler. Applies only to crawlers implementing the eliashaeussler-cachewarmup-crawler-configurablecrawlerinterface. For more information read Configurable crawlers.

verboseCrawler

verboseCrawler
type

string (FQCN)

Default

eliashaeussler-typo3warming-crawler-outputtinguseragentcrawler

Verbose crawler to be used for cache warmup from the command-line.

verboseCrawlerOptions

verboseCrawlerOptions
type

string (JSON)

JSON-encoded string of custom crawler options for the verbose crawler. Applies only to crawlers implementing the eliashaeussler-cachewarmup-crawler-configurablecrawlerinterface. For more information read Configurable crawlers.

enablePageTree

enablePageTree
type

boolean

Default

1

Enable cache warmup in the page tree context menu. This affects all users, including administrators.

supportedDoktypes

supportedDoktypes
type

string (comma-separated list)

Default

1

Comma-separated list of doktypes to be supported for cache warmup in the page tree context menu. Defaults to default pages with doktype 1 only. If your project implements custom doktypes, you can add them here to support cache warmup from the context menu.

enableToolbar

enableToolbar
type

boolean

Default

1

Enable cache warmup in the backend toolbar. This affects all users, including administrators.

Site configuration 

The cache warmup is based of the configured sites in the TYPO3 installation. Therefore, in order to control the cache warmup behavior, the site configuration can be used. The following configuration options are available for this purpose:

xml_sitemap_path (site)

xml_sitemap_path (site)
Path

xml_sitemap_path

type

string

Path to the XML sitemap of the configured site's base language. It must be relative to the entry point of the site.

Configuration of XML sitemap path within the Sites module

xml_sitemap_path (site_language)

xml_sitemap_path (site_language)
Path

languages > (site language) > xml_sitemap_path

type

string

Path to the XML sitemap of an additional site language. It must be relative to the entry point of the site language.

Permissions 

Administrators are able to run cache warmup for all available sites and pages. All other users are by default not allowed to run those tasks. Thus, they cannot see both the cache warmup toolbar item and context menu items.

However, you can use User TSconfig to allow cache warmup for specific users/usergroups and sites/pages. Add the following configuration to the options.cacheWarmup User TSconfig:

allowedSites

allowedSites
Path

options.cacheWarmup.allowedSites

type

string (comma-separated list)

Provide a comma-separated list of site identifiers. Those sites can then be warmed by the backend user.

Example:

options.cacheWarmup.allowedSites = my-dummy-site,another-dummy-site
Copied!

allowedPages

allowedPages
Path

options.cacheWarmup.allowedPages

type

string (comma-separated list)

Provide a comma-separated list of pages. Those pages can then be warmed by the backend user. Pages can be suffixed by a + sign to recursively include all subpages.

Example:

options.cacheWarmup.allowedPages = 1,2,3+
Copied!

Backend toolbar 

As soon as the extension is installed, a new toolbar item in your TYPO3 backend should appear. You can click on the toolbar item to get a list of all sites. If a site does not provide an XML sitemap, it cannot be used to warm up caches.

Cache warmup toolbar item within the TYPO3 backend

Page tree 

Next to the item in the backend toolbar, one can also trigger cache warmup using the context menu of pages inside the page tree.

Cache warmup context meu items within the page tree

Console commands 

The extension provides the following console commands:

warming:cachewarmup 

A command to trigger cache warmup of single pages and/or whole sites using their XML sitemaps.

vendor/bin/typo3 warming:cachewarmup
Copied!
typo3/sysext/core/bin/typo3 warming:cachewarmup
Copied!

The following command options are available:

-p|--pages

-p|--pages
Required

false

type

integer

Default

none

Multiple allowed

true

Use this option to provide IDs of pages whose Frontend caches should be warmed up. You can pass this option multiple times, either as single integer values or as a comma-separated list of integer values.

Example:

vendor/bin/typo3 warming:cachewarmup -p 1 -p 2 -p 3
vendor/bin/typo3 warming:cachewarmup -p 1,2,3
Copied!
typo3/sysext/core/bin/typo3 warming:cachewarmup -p 1 -p 2 -p 3
typo3/sysext/core/bin/typo3 warming:cachewarmup -p 1,2,3
Copied!

-s|--sites

-s|--sites
Required

false

type

integer or string (site identifier)

Default

none

Multiple allowed

true

Use this option to provide a list of sites to be warmed up. You can either pass the appropriate site identifiers or the site's root page IDs.

Example:

vendor/bin/typo3 warming:cachewarmup -s my-cool-site
vendor/bin/typo3 warming:cachewarmup -s 1
Copied!
typo3/sysext/core/bin/typo3 warming:cachewarmup -s my-cool-site
typo3/sysext/core/bin/typo3 warming:cachewarmup -s 1
Copied!

-l|--languages

-l|--languages
Required

false

type

integer

Default

-1 (all languages)

Multiple allowed

true

You can optionally limit the languages of sites to be warmed up to a given list of language IDs. If this option is omitted, all site languages will be included in the cache warmup.

Example:

vendor/bin/typo3 warming:cachewarmup -l 0 -l 1
vendor/bin/typo3 warming:cachewarmup -l 0,1
Copied!
typo3/sysext/core/bin/typo3 warming:cachewarmup -l 0 -l 1
typo3/sysext/core/bin/typo3 warming:cachewarmup -l 0,1
Copied!

--limit

--limit
Required

false

type

integer

Default

limit value from extension configuration

Multiple allowed

false

Maximum number of pages to be crawled. Set to 0 to disable the limit. If this option is omitted, the limit value from extension configuration is used.

-x|--strict

-x|--strict
Required

false

type

boolean

Default

false

Multiple allowed

false

Exit with a non-zero status code in case cache warmup fails or errors occur during cache warmup.

warming:showuseragent 

A command that shows the custom User-Agent header that is used for cache warmup requests by default crawlers.

vendor/bin/typo3 warming:showuseragent
Copied!
typo3/sysext/core/bin/typo3 warming:showuseragent
Copied!

Using the API 

Besides the usage via the TYPO3 backend and the console commands, there is also a public PHP API. It can be used to execute the cache warmup directly in PHP code.

class CacheWarmupService
Fully qualified name
\EliasHaeussler\Typo3Warming\Service\CacheWarmupService

Service to run cache warmup for sites and pages.

warmupSites ( $sites, $request)

Run cache warmup for given list of sites.

param array $sites

List of sites to be warmed up.

param EliasHaeussler\\Typo3Warming\\Request\\WarmupRequest $request

Additional cache warmup request parameters.

returntype

EliasHaeussler\CacheWarmup\Crawler\CrawlerInterface

warmupPages ( $pageIds, $request)

Run cache warmup for given list of pages.

param array $pageIds

List of pages to be warmed up.

param EliasHaeussler\\Typo3Warming\\Request\\WarmupRequest $request

Additional cache warmup request parameters.

returntype

EliasHaeussler\CacheWarmup\Crawler\CrawlerInterface

generateUri ( $pageId, $languageId = null)

Generate uri for given page and optional language.

param int $pageId

ID of the page for which the uri is to be generated.

param int $languageId

Optional language ID to respect when generating the uri.

returntype

Psr\Http\Message\UriInterface

getCrawler ( )

Return crawler being used for cache warmup.

returntype

Psr\Http\Message\UriInterface

setCrawler ( $crawler)

Set crawler to use for cache warmup.

param string|EliasHaeussler\\CacheWarmup\\Crawler\\CrawlerInterface $crawler

The crawler to use for cache warmup.

Returns

The service object (fluent setter).

Example 

use EliasHaeussler\Typo3Warming;
use TYPO3\CMS\Core;

$cacheWarmupService = Core\Utility\GeneralUtility::makeInstance(Typo3Warming\Service\CacheWarmupService::class);
$request = new Typo3Warming\Request\WarmupRequest();

// Get all sites
$siteFinder = Core\Utility\GeneralUtility::makeInstance(Core\Site\SiteFinder::class);
$sites = $siteFinder->getAllSites();

// Run cache warmup for all sites
$crawler = $cacheWarmupService->warmupSites($sites, $request);

// Run cache warmup for single pages only
$crawler = $cacheWarmupService->warmupPages([1, 2, 3], $request);

// Evaluate crawling states
$failedUrls = $crawler->getFailedUrls();
$successfulUrls = $crawler->getSuccessfulUrls();
Copied!

Crawlers 

The extension uses crawlers to visit all URLs configured for cache warmup. While visiting a URL, the appropriate page cache gets warmed. Learn more about which crawlers are available by default and how to implement a custom crawler on this page.

interface CrawlerInterface
Fully qualified name
\EliasHaeussler\CacheWarmup\Crawler\CrawlerInterface

Interface for crawlers used to crawl and warm up URLs.

crawl ( $urls)

Crawl a given list of URLs.

param array $urls

List of URLs to be crawled.

getSuccessfulUrls ( )

Return all successfully crawled URLs.

Returns

A list of eliashaeussler-cachewarmup-crawlingstate instances

getFailedUrls ( )

Return all failing crawled URLs.

Returns

A list of eliashaeussler-cachewarmup-crawlingstate instances

Default crawlers 

The extension ships with two default crawlers:

  • eliashaeussler-typo3warming-crawler-concurrentuseragentcrawler: Used for cache warmup triggered within the TYPO3 backend
  • eliashaeussler-typo3warming-crawler-outputtinguseragentcrawler: Used for cache warmup executed from the command-line

Both crawlers use a custom User-Agent header for all warmup requests. By using this custom header, it is possible to exclude warmup requests from the statistics of analysis tools, for example. The header is generated by a HMAC hash of the string TYPO3/tx_warming_crawler.

The generated header value can be copied in the dropdown of the toolbar item in the backend. Alternatively, a command warming:showuseragent is available which can be used to read the current User-Agent header.

Implement a custom crawler 

Available interfaces 

The actual cache warmup is done via the library eliashaeussler/cache-warmup. It provides the \EliasHaeussler\CacheWarmup\Crawler\CrawlerInterface, which must be implemented when developing your own crawler. There is also a eliashaeussler-cachewarmup-crawler-verbosecrawlerinterface that redirects user-oriented output to an instance of symfony-component-console-output-outputinterface.

Configurable crawlers 

Since version 0.7.13 of eliashaeussler/cache-warmup, custom crawlers can also implement the eliashaeussler-cachewarmup-crawler-configurablecrawlerinterface, allowing users to configure warmup requests themselves.

Steps to implement a new crawler 

  1. Create a new crawler

    The new crawler must implement one of the following interfaces:

  2. Configure the new crawler

    Add the new crawler to the extension configuration. Note that you should configure either the crawler or verboseCrawler option, depending on what interface you have implemented.

  3. Flush system caches

    Finally, flush all system caches to ensure the correct crawler class is used for further cache warmup requests.

Sitemap providers 

To localize the sitemap of a site, so-called "sitemap providers" are available. These are executed one after the other (depending on priority) to localize XML sitemaps according to certain criteria.

interface ProviderInterface
Fully qualified name
\EliasHaeussler\Typo3Warming\Sitemap\Provider\ProviderInterface

Interface for sitemap providers used to locate the path to an XML sitemap of a given site.

get ( $site, $siteLanguage = null)

Locate the XML sitemap path of the given site.

param TYPO3\\CMS\\Core\\Site\\Entity\\Site $site

The site whose XML sitemap path should be located.

param TYPO3\\CMS\\Core\\Site\\Entity\\SiteLanguage $siteLanguage

An optional site language to include while locating the XML sitemap path.

Returns

An instance of eliashaeussler-typo3warming-sitemap-siteawaresitemap or null.

getPriority ( )

Get the provider's priority. The higher the returned value, the earlier the provider will be executed in the sitemap location process.

returntype

int

Default providers 

By default, the path to an XML sitemap is determined in three steps:

  1. Site configuration

    Within the Sites module, one can explicitly define the path to the XML sitemap of a site.

    Configuration of XML sitemap path within the Sites module
  2. robots.txt

    If no path is defined in the site configuration, a possible robots.txt file is parsed for a valid Sitemap specification. Read more at sitemaps.org.

  3. Default path

    If none of the above methods are successful, the default path sitemap.xml is used.

Implement a custom provider 

To develop your own sitemap provider, it is only necessary to implement the \EliasHaeussler\Typo3Warming\Sitemap\Provider\ProviderInterface. In addition, the getPriority() method must be used to define when the provider is executed.

The order of the providers provided by default is as follows:

Sitemap provider Priority
eliashaeussler-typo3warming-sitemap-provider-siteprovider 200
eliashaeussler-typo3warming-sitemap-provider-robotstxtprovider 100
eliashaeussler-typo3warming-sitemap-provider-defaultprovider PHP_INT_MIN |

Once your custom provider is ready, make sure to clear the DI caches in order to rebuild the service container properly.

Caching 

Once a sitemap is located by a sitemap provider, the path to the XML sitemap is cached. This speeds up following warmup requests. Caching happens with the core cache which defaults to a filesystem cached located at var/cache/code/core/tx_warming.php.

class CacheManager
Fully qualified name
\EliasHaeussler\Typo3Warming\Cache\CacheManager

Manager to read and write the core cache tx_warming.

get ( $site = null, $siteLanguage = null)

Get all located sitemaps or the located sitemap of a given site and/or site language.

param TYPO3\\CMS\\Core\\Site\\Entity\\Site $site

The sitemap's site object or NULL to lookup all sitemaps.

param TYPO3\\CMS\\Core\\Site\\Entity\\SiteLanguage $siteLanguage

An optional site language

Returns

Either an array of all located sitemaps or the located sitemap of a given site.

set ( $sitemap)

Add the located sitemap to the tx_warming cache.

param EliasHaeussler\\Typo3Warming\\Sitemap\\SiteAwareSitemap $sitemap

The located sitemap to be cached.

Configuration API 

In order to access the extension configuration, a slim PHP API exists. Each configuration option is accessible by an appropriate class method.

class Configuration
Fully qualified name
\EliasHaeussler\Typo3Warming\Configuration\Configuration

API to access all available extension configuration options.

getLimit ( )

Get the configured crawler limit.

returntype

int

getCrawler ( )

Get the configured crawler class.

returntype

class-string<EliasHaeusslerCacheWarmupCrawlerCrawlerInterface>

getCrawlerOptions ( )

Get the configured crawler options.

returntype

array

getVerboseCrawler ( )

Get the configured verbose crawler class.

returntype

class-string<EliasHaeusslerCacheWarmupCrawlerVerboseCrawlerInterface>

getVerboseCrawlerOptions ( )

Get the configured verbose crawler options.

returntype

array

getUserAgent ( )

Get the calculated user-agent.

returntype

string

getAll ( )

Get all extension configuration options of this extension.

returntype

array

AccessUtility 

The AccessUtility can be used to determine permissions of the current user to warm up caches of specific sites or pages.

class AccessUtility
Fully qualified name
\EliasHaeussler\Typo3Warming\Utility\AccessUtility

Utility class to determine cache warmup permissions.

canWarmupCacheOfPage ( $pageId, $languageId = null)

Check if the current user can warm up caches of the given page.

param int $pageId

ID of the page to be checked.

param int $languageId

Optional language ID to be included in the check.

canWarmupCacheOfSite ( $site, $languageId = null)

Check if the current user can warm up caches of the given site.

param TYPO3\\CMS\\Core\\Site\\Entity\\Site $site

The site to be checked.

param int $languageId

Optional language ID to be included in the check.

Contributing 

Thanks for considering contributing to this extension! Since it is an open source product, its successful further development depends largely on improving and optimizing it together.

The development of this extension follows the official TYPO3 coding standards. To ensure the stability and cleanliness of the code, various code quality tools are used and most components are covered with test cases.

Create an issue first 

Before you start working on the extension, please create an issue on GitHub: https://github.com/eliashaeussler/typo3-warming/issues

Also, please check if there is already an issue on the topic you want to address.

Contribution workflow 

Preparation 

Clone the repository first:

git clone https://github.com/eliashaeussler/typo3-warming.git
cd typo3-warming
Copied!

Now install all Composer dependencies:

composer install
Copied!

Next, install all Node dependencies:

yarn --cwd Resources/Private/Frontend
Copied!

Check code quality 

TYPO3 

# Run all linters
composer lint

# Run Composer linter only
composer lint:composer

# Run PHP linter only
composer lint:php

# Run TypoScript linter only
composer lint:typoscript

# Run PHP static code analysis
composer sca
Copied!

Frontend 

# Run all linters
yarn --cwd Resources/Private/Frontend lint
yarn --cwd Resources/Private/Frontend lint:fix

# Run SCSS linter only
yarn --cwd Resources/Private/Frontend lint:scss
yarn --cwd Resources/Private/Frontend lint:scss:fix

# Run TypeScript linter only
yarn --cwd Resources/Private/Frontend lint:ts
yarn --cwd Resources/Private/Frontend lint:ts:fix
Copied!

Run tests 

# Run tests
composer test

# Run tests with code coverage
composer test:ci
Copied!

The code coverage reports will be stored in .Build/log/coverage.

Build documentation 

# Rebuild and open documentation
composer docs

# Build documentation (from cache)
composer docs:build

# Open rendered documentation
composer docs:open
Copied!

The built docs will be stored in .Build/docs.

Pull Request 

When you have finished developing your contribution, simply submit a pull request on GitHub: https://github.com/eliashaeussler/typo3-warming/pulls

Sitemap