Skip to content
mFilter
mFilter
Faceted filtering for MODX 3 with SEO URL support
  1. Extras
  2. mFilter

Version 1.2.0: filter cache warmup

Major update adding a cache warmup system so catalog pages load instantly on first visit.

Problem

MySQL 8 can be slow on large catalogs. First load of a filtered page took 15–60 seconds for catalogs over 10 000 products. Bottlenecks:

  • Loading category product IDs (ElementRunner::getIds())
  • Computing available filter values (Filter::getFilters())
  • Computing facet counters (Filter::getSuggestionsForIds())

Solution

The warmup system precomputes and stores all three heavy steps in the database. Warmup runs in the background via Scheduler or manually from the manager. After warmup, catalog pages open in fractions of a second.


New features

Warmup subsystem

An administrator creates a warmup configuration in the new manager tab, specifying the snippet and catalog pages. During warmup the system iterates bound pages and caches:

  1. baseIds — product IDs in the category
  2. filter values — values for the filter form
  3. suggestions — product count per filter value

Auto-created configurations

On first visit to any catalog page, a warmup configuration is created automatically. You do not need to configure every page manually — crawl the catalog once or wait for user traffic.

Snippet call parser

The “Snippet call” field in the configuration editor accepts template code and extracts parameters. Three formats are supported:

fenom
{'!mFilter'|snippet:['element' => 'msProducts', 'parents' => $_modx->resource.id]}
[[!mFilter? &element=`msProducts` &parents=`5`]]
json
{"element": "msProducts", "parents": 5}

Scheduler task

New task mfl_warmup runs warmup on cron in the background. By default it is recurring — every 50 minutes, refreshing cache before TTL expires.

The manager includes Via Scheduler to queue warmup in the background.

“Cache warmup” tab

New tab in mFilter:

  • Configuration table with last warmup info
  • Editor with call parsing, parameter table, and resource tree
  • Warm all, Via Scheduler, per-configuration warmup
  • + counters checkbox (on by default)

More about the UI →


New database models

TableDescription
mfl_warmup_configsWarmup configs (element, params, cache_key_hash, stats)
mfl_warmup_config_resourcesConfig to catalog page bindings (many-to-many)

Tables are created automatically on install or upgrade.


API

10 new endpoints for configuration management:

MethodRouteDescription
GET/warmup-configsList configurations
GET/warmup-configs/{id}Get configuration
POST/warmup-configsCreate
PUT/warmup-configs/{id}Update
DELETE/warmup-configs/{id}Delete
POST/warmup-configs/{id}/warmupWarm one configuration
POST/warmup-configs/warmup-allWarm all
POST/warmup-configs/scheduleSchedule via Scheduler
POST/warmup-configs/parse-snippetParse snippet call
GET/warmup-configs/resource-treeResource tree

Improvements

Caching getSuggestionsForIds

Filter::getSuggestionsForIds() now stores results in mfl_cache. Repeated calls with the same parameters read from cache.

UTC cache timestamps

All cache timestamps (expires_at, created_at, updated_at) are stored in UTC via gmdate(). Fixes premature cache expiry when cron runs in UTC and web processes use a local timezone.

TvIndexer

TvIndexer::indexResource() now indexes only TVs used in filter configuration instead of all resource TVs. Reduces indexing load.

Legacy warm_suggestions removed

Removed legacy HTTP-based suggestion warmup (file_get_contents with SSL verification disabled). Replaced with direct execution via mfl_warmup.


Project tuning

Warmup interval and TTL

Catalog sizeTTLWarmup intervalDescription
Up to 1 000 products36003000Default
1 000 — 10 00072006000Every 100 min
10 000 — 100 0001440010800Every 3 hours
100 000+8640043200Twice per day
  • TTL — system setting mfilter.cache_lifetime
  • Intervalinterval field on Scheduler task mfl_warmup

Внимание

Interval must be less than TTL. Account for warmup duration — for ~200 000 products warmup can take ~30 minutes.

When the product catalog changes

ScenarioAction
Regular price/stock importAutomatic — recurring task refreshes cache
Bulk new product importRun warmup manually from the manager
Filter structure changedClear cache + run warmup

Upgrade

Before upgrading

  1. Back up the database

After upgrading

  1. Clear MODX cache
  2. Open the Cache warmup tab
  3. Create a configuration or wait for auto-creation when the catalog is visited
  4. Run warmup Via Scheduler
  5. Ensure cron is configured for Scheduler

New tables

mfl_warmup_configs and mfl_warmup_config_resources are created automatically when the package is installed.

New Scheduler task

Task mfl_warmup is registered automatically. Without Scheduler, warmup is only available from the manager (Warm all).

Results

After warmup on a catalog of 200 000 products and 100 categories:

MetricWithout warmupWith warmup
First page load15–60 sec< 1 sec
Full catalog warmup~8–30 min (background)