CachePurger
in package
Purges the WP Rocket page cache for products the PIM changed.
WP Rocket cannot see these pages change. Product URLs are custom rewrites onto one shared product_templ post, so its post-based purge only ever reaches that post's permalink, never /tv/65fp2ea/. And the content itself lives in TypeSense, which fires no WordPress hook at all. Without this, caching product pages (mu-plugins/wp-rocket-customizations.php) would serve stale prices and specs until the cache lifespan expired.
Shaped like DatasheetNotifier: accumulate during the request, act once on shutdown.
Deliberately never escalates to a whole-site purge. Dropping a locale's homepage and listings would send every subsequent visitor through a full render at once, which is the pile-up on a small FPM pool that caching these pages exists to prevent. Past the cap we log and leave it to a human instead.
Table of Contents
Constants
- LOG_CHANNEL : mixed = 'wsc-cache-purge'
- MAX_URLS : mixed = 2000
- Past this many distinct URLs in one run we stop collecting. A full populate rewrites the whole catalogue in every locale, and purging that is a cache flush by another name.
- SLUG_ALIAS_BASE : mixed = 'product_cards'
- Only the localized card collection carries the frontend slug; every other collection is either global or has no URL of its own.
Properties
- $overCap : bool
- $slugs : array<int, array<string, true>>
- Slugs recorded so far, keyed blogId => slug => true so repeats collapse.
Methods
- buildUrls() : array<int, array<int, string>>
- Resolves everything recorded so far into absolute URLs, keyed by blog.
- flush() : void
- recordDocumentWrite() : void
- A document landed in TypeSense. Called from Collection::populateDocument().
- reset() : void
- count() : int
Constants
LOG_CHANNEL
public
mixed
LOG_CHANNEL
= 'wsc-cache-purge'
MAX_URLS
Past this many distinct URLs in one run we stop collecting. A full populate rewrites the whole catalogue in every locale, and purging that is a cache flush by another name.
private
mixed
MAX_URLS
= 2000
SLUG_ALIAS_BASE
Only the localized card collection carries the frontend slug; every other collection is either global or has no URL of its own.
private
mixed
SLUG_ALIAS_BASE
= 'product_cards'
Properties
$overCap
private
static bool
$overCap
= false
$slugs
Slugs recorded so far, keyed blogId => slug => true so repeats collapse.
private
static array<int, array<string, true>>
$slugs
= []
Methods
buildUrls()
Resolves everything recorded so far into absolute URLs, keyed by blog.
public
static buildUrls() : array<int, array<int, string>>
Pure — no filesystem, no WP Rocket — so the mapping is testable on its own.
Return values
array<int, array<int, string>>flush()
public
static flush() : void
recordDocumentWrite()
A document landed in TypeSense. Called from Collection::populateDocument().
public
static recordDocumentWrite(string $aliasBase, int $blogId, array<int, array<string, mixed>> $tsData) : void
Parameters
- $aliasBase : string
- $blogId : int
- $tsData : array<int, array<string, mixed>>
-
The documents as written.
reset()
public
static reset() : void
count()
private
static count() : int