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 EliasHaeussler\Typo3Warming\Service\CacheWarmupService

Service to run cache warmup for sites and pages.

warmup($sites, $pages, $limit, $strategy)

Run cache warmup for given sites and pages.

Parameters
  • $sites (array) -- List of site warmup requests.

  • $pages (array) -- List of page warmup requests.

  • $limit (int) -- Optional cache warmup limit.

  • $strategy (string) -- Optional crawling strategy.

Return type

EliasHaeussler\Typo3Warming\Result\CacheWarmupResult

getCrawler()

Return crawler being used for cache warmup.

Return type

Psr\Http\Message\UriInterface

setCrawler($crawler)

Set crawler to use for cache warmup.

Parameters
  • $crawler (string|EliasHaeussler\CacheWarmup\Crawler\CrawlerInterface) -- The crawler to use for cache warmup.

Returns

The service object (fluent setter).

Example

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

$cacheWarmupService = Core\Utility\GeneralUtility::makeInstance(Typo3Warming\Service\CacheWarmupService::class);
$siteFinder = Core\Utility\GeneralUtility::makeInstance(Core\Site\SiteFinder::class);

$sites = [];
$pages = [];

// Create site warmup requests
foreach ($siteFinder->getAllSites() as $site) {
    $sites[] = new Typo3Warming\ValueObject\Request\SiteWarmupRequest($site);
}

// Create page warmup requests
foreach ([1, 2, 3] as $page) {
    $pages[] = new Typo3Warming\ValueObject\Request\PageWarmupRequest($page);
}

// Define optional cache warmup options
$limit = 100;
$strategy = CacheWarmup\Crawler\Strategy\SortByPriorityStrategy::getName();

// Run cache warmup for sites and pages
$result = $cacheWarmupService->warmup($sites, $pages, $limit, $strategy);

// Fetch crawling states
$failedUrls = $result->getResult()->getFailed();
$successfulUrls = $result->getResult()->getSuccessful();

// Fetch excluded URLs
$excludedUrls = $result->getExcludedUrls();