PHPackages                             blackbird/module-cache-warmer - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Caching](/categories/caching)
4. /
5. blackbird/module-cache-warmer

ActiveMagento2-module[Caching](/categories/caching)

blackbird/module-cache-warmer
=============================

A Magento 2 module that improves store performance by automatically warming cache through intelligent page crawling and async refresh mechanisms.

1.0.6(8mo ago)51.1k↓41.7%1MITPHPPHP ^8.1

Since Jun 6Pushed 8mo ago1 watchersCompare

[ Source](https://github.com/blackbird-agency/magento-2-cache-warmer)[ Packagist](https://packagist.org/packages/blackbird/module-cache-warmer)[ RSS](/packages/blackbird-module-cache-warmer/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (8)Used By (0)

Blackbird Cache Warmer
======================

[](#blackbird-cache-warmer)

[![Latest Stable Version](https://camo.githubusercontent.com/d90f7efaa6334635eb269cd739d7e7c3d4f475e87ca67845ffd3628f84fcf97e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f626c61636b626972642f6d6f64756c652d63616368652d7761726d65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/blackbird/module-cache-warmer)[![License: MIT](https://camo.githubusercontent.com/2ff5d8dd043d25777230c61ac58760eba4da31e26ee28f7ddc26f1932cdabdb0/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f626c61636b626972642d6167656e63792f6d6167656e746f2d322d63616368652d7761726d65722e7376673f7374796c653d666c61742d737175617265)](./LICENSE.txt)

This module provides functionality to warm up the cache by crawling pages of your Magento store. It helps improve the performance of your store by ensuring that cache is pre-populated, resulting in faster page load times for your customers.

Key functionality includes:

- Crawling pages of your Magento store to warm up the cache
- Configuring basic authentication for crawling
- Setting concurrency for crawling
- Enabling/disabling store switching
- Configuring customer credentials for authenticated crawling
- Automatic async cache refresh for entities (products, categories, CMS pages, etc.)
- Automatic cache warming when full\_page cache is flushed from the admin panel
- Slack webhook notifications for cache warming errors

The source code is available at the [GitHub repository](https://github.com/blackbird-agency/magento-2-cache-warmer).

---

Setup
-----

[](#setup)

### Get the Package

[](#get-the-package)

#### **Zip Package:**

[](#zip-package)

Unzip the package into `app/code/Blackbird/CacheWarmer`, from the root of your Magento instance.

#### **Composer Package:**

[](#composer-package)

```
composer require blackbird/module-cache-warmer
```

### Install the Module

[](#install-the-module)

Go to your Magento root directory, then run the following Magento commands:

**If you are in production mode, do not forget to recompile and redeploy the static resources, or to use the `--keep-generated` option.**

```
bin/magento module:enable Blackbird_CacheWarmer
bin/magento setup:upgrade
bin/magento cache:flush
```

Features
--------

[](#features)

### Cache Warming

[](#cache-warming)

The Cache Warmer module crawls pages of your Magento store to warm up the cache. This helps improve the performance of your store by ensuring that cache is pre-populated, resulting in faster page load times for your customers.

### Configurable Crawling

[](#configurable-crawling)

The module provides various configuration options for crawling:

- Basic authentication for crawling
- Concurrency for crawling (number of concurrent requests)
- Store switching (enable/disable)
- Customer credentials for authenticated crawling
- Crawling for not logged in users (enable/disable)
- Default collector type (Sitemap or Product)

### Automatic Async Cache Refresh for Entities

[](#automatic-async-cache-refresh-for-entities)

The module includes a feature that automatically triggers an asynchronous cache refresh for entities (products, categories, CMS pages) when their Varnish cache is cleaned. This ensures that entity pages are quickly re-cached after cache invalidation, maintaining optimal performance for your store.

#### How it works:

[](#how-it-works)

1. When an entity's cache is invalidated in Varnish (through the \\Magento\\CacheInvalidate\\Observer\\InvalidateVarnishObserver), the module detects this and adds the entity to a queue.
2. A cron job runs every minute to process the queue and warm the cache for these entities.
3. The queue is stored in a dedicated database table (`blackbird_cachewarmer_entity_queue`), ensuring reliability and persistence.

#### Supported Entity Types:

[](#supported-entity-types)

- Products
- Categories
- CMS Pages

### Automatic Cache Warming on Full Page Cache Flush

[](#automatic-cache-warming-on-full-page-cache-flush)

The module includes a feature that automatically triggers cache warming when the full\_page cache is flushed from the admin panel. This ensures that your store's pages are quickly re-cached after a cache flush, maintaining optimal performance.

#### How it works:

[](#how-it-works-1)

1. When the full\_page cache is flushed from the admin panel (either through "Flush Magento Cache" or "Flush Cache Storage"), the module detects this event.
2. The module sets a flag in the database to indicate that cache warming should be triggered.
3. A cron job runs every minute to check if cache warming should be triggered.
4. If cache warming is triggered, the cron job warms the cache for all urls as the command does.
5. The module uses a timestamp-based flag system to:
    - Ensure that only one cache warming process runs at a time
    - Automatically kill any process that has been running for more than 6 hours

### Custom Logging

[](#custom-logging)

The module provides custom logging to `warmer.log` with configurable log levels. You can select the log level for `warmer.log` (default: error). Messages with this level and higher will be logged to `var/log/warmer.log`.

### Slack Webhook Notifications

[](#slack-webhook-notifications)

The module can send notifications to Slack when cache warming encounters errors. This helps administrators monitor the cache warming process and quickly identify and resolve issues.

#### How it works:

[](#how-it-works-2)

1. When cache warming encounters errors, the module sends a notification to the configured Slack webhook URL.
2. The notification includes a message indicating that errors occurred and advises checking the logs for more details.
3. This feature can be enabled/disabled in the module configuration.

---

Usage
-----

[](#usage)

### Configuration

[](#configuration)

The module can be configured in the Magento admin panel under **Stores &gt; Configuration &gt; Blackbird Extensions &gt; Cache Warmer**.

#### General Configuration

[](#general-configuration)

- **Basic Auth Username**: Username for basic authentication
- **Basic Auth Password**: Password for basic authentication
- **Concurrency**: Number of concurrent requests (default: 1)
- **Switch Store**: Enable/disable store switching (default: disabled)
- **Instances**: Instances configuration
- **Customer Credentials**: Customer credentials for authentication (format: username:password)
- **Disable Not Logged In Crawl**: Enable/disable crawling for not logged in users (default: disabled)
- **Default Collector Type**: Select the default collector type (Sitemap or Product) or leave empty for no default
- **Enable Slack Webhook Notifications**: Enable/disable notifications to Slack when cache warming encounters errors (default: disabled)
- **Slack Webhook URL**: URL of the Slack webhook to send notifications to

#### Logging Configuration

[](#logging-configuration)

- **Log Level**: Select the log level for warmer.log (default: error). Messages with this level and higher will be logged to var/log/warmer.log

### Console Commands

[](#console-commands)

The module provides console commands to run the cache warmer:

```
bin/magento blackbird:cachewarmer:run
```

---

Extending with Custom Collector Types
-------------------------------------

[](#extending-with-custom-collector-types)

The module provides an extensible architecture that allows third-party modules to add their own collector types. To add a custom collector type, follow these steps:

1. Create a class that implements `Blackbird\CacheWarmer\Api\UrlCollectorInterface`:

```
