eliashaeussler/cache-warmup

Composer package to warm up website caches, based on a given sitemap.xml

0.5.1 2021-04-29 14:48 UTC

This package is auto-updated.

Last update: 2021-08-29 15:32:25 UTC


README

Pipeline Coverage Packagist Docker License

Cache warmup

Composer package to warm up caches of pages located in XML sitemaps

Installation

composer req --dev eliashaeussler/cache-warmup

Usage

Command-line usage

General usage

./vendor/bin/cache-warmup [--urls...] [--limit] [--progress] [--crawler] [<sitemaps>...]

Extended usage

# Warm up caches of specific sitemap
./vendor/bin/cache-warmup "https://www.example.org/sitemap.xml"

# Limit number of pages to be crawled
./vendor/bin/cache-warmup "https://www.example.org/sitemap.xml" --limit 50

# Show progress bar (can also be achieved by increasing verbosity)
./vendor/bin/cache-warmup "https://www.example.org/sitemap.xml" --progress
./vendor/bin/cache-warmup "https://www.example.org/sitemap.xml" -v

# Use custom crawler (must implement EliasHaeussler\CacheWarmup\Crawler\CrawlerInterface)
./vendor/bin/cache-warmup "https://www.example.org/sitemap.xml" --crawler "Vendor\Crawler\MyCrawler"

# Define URLs to be crawled
./vendor/bin/cache-warmup -u "https://www.example.org/" \
    -u "https://www.example.org/foo" \
    -u "https://www.example.org/baz"

For more detailed information run ./vendor/bin/cache-warmup --help.

Code usage

General usage

// Instantiate and run cache warmer
$cacheWarmer = new \EliasHaeussler\CacheWarmup\CacheWarmer();
$cacheWarmer->addSitemaps('https://www.example.org/sitemap.xml');
$crawler = $cacheWarmer->run();

// Get successful and failed URLs
$successfulUrls = $crawler->getSuccessfulUrls();
$failedUrls = $crawler->getFailedUrls();

Extended usage

// Limit number of pages to be crawled
$cacheWarmer->setLimit(50);

// Use custom crawler (must implement EliasHaeussler\CacheWarmup\Crawler\CrawlerInterface)
$crawler = new \Vendor\Crawler\MyCrawler();
$cacheWarmer->run($crawler);

// Define URLs to be crawled
$cacheWarmer->addUrl(new \GuzzleHttp\Psr7\Uri('https://www.example.org/'));
$cacheWarmer->addUrl(new \GuzzleHttp\Psr7\Uri('https://www.example.org/foo'));
$cacheWarmer->addUrl(new \GuzzleHttp\Psr7\Uri('https://www.example.org/baz'));

Usage with Docker

General usage

docker run --rm -it eliashaeussler/cache-warmup <options>

Extended usage

# Use latest version
docker run --rm -it eliashaeussler/cache-warmup:latest <options>

# Use specific version
docker run --rm -it eliashaeussler/cache-warmup:0.3.0 <options>

Usage with docker-compose

version: '3.6'

services:
  cache-warmup:
    image: eliashaeussler/cache-warmup
    command: [<options>]

Development

Preparation

# Clone repository
git clone https://gitlab.elias-haeussler.de/eliashaeussler/cache-warmup.git
cd cache-warmup

# Install Composer dependencies
composer install

Run linters

# Composer normalization
composer normalize

# PHP-CS Fixer
composer lint

# PHPStan
composer sca

Run tests

Unit tests of this plugin can be executed using the provided Composer script test. You can pass all available arguments to PHPUnit.

# Run tests
composer test

# Run tests and print coverage result
composer test -- --coverage-text

License

GPL 3.0 or later