Developer Reference
Comprehensive reference for all developer APIs in Mamba Cache for WooCommerce — including 70+ filters & actions, WP-CLI commands, and REST API endpoints.
Usage
All hooks follow standard WordPress conventions. Filters must always return a value of the same type as received. Add hooks in your theme’s functions.php or a custom plugin. Click any hook name to expand its parameters and code example.
Cache Configuration
11 filtersControl cache TTL, size limits, headers, cookies, and query parameter handling.
Customize the cache TTL (time-to-live) for specific requests. Useful for giving shorter or longer cache lifetimes to particular URL patterns.
| Parameter | Type | Description |
|---|---|---|
| $ttl | int | Default TTL in seconds |
| $request_uri | string | Current request URI |
add_filter('mamba_cache_ttl_for_request', function($ttl, $uri) {
if (strpos($uri, '/shop/') !== false) {
return 3600; // 1 hour for shop pages
}
return $ttl;
}, 10, 2);Customize the browser cache TTL sent in Cache-Control headers to the client.
| Parameter | Type | Description |
|---|---|---|
| $ttl | int | Browser TTL in seconds |
add_filter('mamba_browser_ttl', function($ttl) {
return 300; // 5-minute browser cache
});Set the maximum cache size in bytes before automatic cleanup is triggered.
| Parameter | Type | Description |
|---|---|---|
| $limit | int | Size limit in bytes |
add_filter('mamba_cache_size_limit', function($limit) {
return 500 * 1024 * 1024; // 500 MB
});Set the stale-while-revalidate window in seconds.
| Parameter | Type | Description |
|---|---|---|
| $window | int | Lock window in seconds |
add_filter('mamba_cache_stale_lock_window', function($window) {
return 300; // 5 minutes
});Customize the default Cache-Control header value.
| Parameter | Type | Description |
|---|---|---|
| $header | string | Cache-Control header value |
add_filter('mamba_cache_default_cache_control', function($header) {
return 'public, max-age=3600, s-maxage=86400';
});Define which response headers should be cached alongside the page content.
| Parameter | Type | Description |
|---|---|---|
| $headers | array | Array of header names |
add_filter('mamba_cache_header_whitelist', function($headers) {
$headers[] = 'X-Custom-Header';
return $headers;
});Define cookies that prevent caching when present.
| Parameter | Type | Description |
|---|---|---|
| $cookies | array | Array of cookie name patterns |
add_filter('mamba_cache_block_on_cookies', function($cookies) {
$cookies[] = 'my_custom_session';
return $cookies;
});Define which query parameters should be included in cache keys.
| Parameter | Type | Description |
|---|---|---|
| $params | array | Array of parameter names |
add_filter('mamba_cacheable_query_params', function($params) {
$params[] = 'custom_filter';
return $params;
});Define tracking parameters to strip from cache keys.
| Parameter | Type | Description |
|---|---|---|
| $params | array | Array of tracking parameter names |
add_filter('mamba_tracking_params', function($params) {
$params[] = 'my_tracking_id';
return $params;
});Whether to honor client Cache-Control: no-cache requests.
| Parameter | Type | Description |
|---|---|---|
| $honor | bool | Whether to honor no-cache |
add_filter('mamba_cache_honor_client_no_cache', '__return_true');Whether to send Content-Length header on cache hits.
| Parameter | Type | Description |
|---|---|---|
| $send | bool | Whether to send header |
add_filter('mamba_cache_send_content_length_on_hit', '__return_false');Cache Variants
5 filtersControl how separate cache entries are created based on language, currency, country, and user role.
Customize the Vary header used to differentiate cache variants.
| Parameter | Type | Description |
|---|---|---|
| $vary | array | Array of Vary header values |
add_filter('mamba_cache_vary', function($vary) {
$vary[] = 'X-Custom-Header';
return $vary;
});Customize the language variant used in cache keys.
| Parameter | Type | Description |
|---|---|---|
| $lang | string|null | Current language code |
add_filter('mamba_variant_lang', function($lang) {
if (isset($_COOKIE['user_lang'])) {
return sanitize_key($_COOKIE['user_lang']);
}
return $lang;
});Customize the currency variant used in cache keys.
| Parameter | Type | Description |
|---|---|---|
| $currency | string|null | Current currency code |
add_filter('mamba_variant_currency', function($currency) {
return get_woocommerce_currency();
});Customize the country variant for cache keys.
| Parameter | Type | Description |
|---|---|---|
| $country | string|null | Current country code |
add_filter('mamba_variant_country', function($country) {
return my_get_user_country();
});Define additional cache dimensions for role-based pricing plugins.
| Parameter | Type | Description |
|---|---|---|
| $dimensions | array | Array of dimension values |
add_filter('mamba_role_based_pricing_dimensions', function($dimensions) {
if (is_user_logged_in()) {
$user = wp_get_current_user();
$dimensions['role'] = $user->roles[0] ?? 'customer';
}
return $dimensions;
});Cache Invalidation
3 filtersControl the scope of cache clearing when content changes.
Customize how many pagination pages to clear when invalidating archives.
| Parameter | Type | Description |
|---|---|---|
| $pages | int | Number of pages to clear |
add_filter('mamba_archive_clear_pages', function($pages) {
return 10;
});Customize how many shop pagination pages to clear.
| Parameter | Type | Description |
|---|---|---|
| $pages | int | Number of pages to clear |
add_filter('mamba_shop_clear_pages', function($pages) {
return 20;
});Define which orderby variants to clear when invalidating shop pages.
| Parameter | Type | Description |
|---|---|---|
| $orderbys | array | Array of orderby values |
add_filter('mamba_shop_clear_orderby', function($orderbys) {
$orderbys[] = 'custom_sort';
return $orderbys;
});Warmup & Preloading
21 filtersControl cache warming behavior — URLs, concurrency, device variants, SSL settings, and priority.
Maximum number of URLs to include in a single warmup job.
| Parameter | Type | Description |
|---|---|---|
| $max | int | Maximum URL count |
add_filter('mamba_warmup_max_urls', function($max) {
return 1000;
});Define which device types to warm.
| Parameter | Type | Description |
|---|---|---|
| $devices | array | Array of device types |
add_filter('mamba_warmup_devices', function($devices) {
return ['desktop', 'mobile'];
});Define which countries to warm for geo-variant caching.
| Parameter | Type | Description |
|---|---|---|
| $countries | array | Array of country codes |
add_filter('mamba_warmup_countries', function($countries) {
return ['US', 'GB', 'DE', 'FR'];
});Whether to exclude out-of-stock products from warmup.
| Parameter | Type | Description |
|---|---|---|
| $exclude | bool | Whether to exclude |
add_filter('mamba_warmup_exclude_outofstock', '__return_true');Filter the final list of URLs before warmup begins.
| Parameter | Type | Description |
|---|---|---|
| $urls | array | Array of URLs to warm |
add_filter('mamba_warmup_filtered_urls', function($urls) {
return array_filter($urls, function($url) {
return strpos($url, '/private/') === false;
});
});Whether to verify SSL certificates during warmup requests.
| Parameter | Type | Description |
|---|---|---|
| $verify | bool | Whether to verify SSL |
add_filter('mamba_warmup_ssl_verify', '__return_false');Maximum number of variants (device/language/currency) per URL.
| Parameter | Type | Description |
|---|---|---|
| $max | int | Maximum variants |
add_filter('mamba_warmup_max_variants', function($max) {
return 5; // More variants for multilingual sites
});Maximum execution time for warmup jobs in seconds.
| Parameter | Type | Description |
|---|---|---|
| $time | int | Max time in seconds |
add_filter('mamba_warmup_max_execution_time', function($time) {
return 1800; // 30 minutes
});Number of concurrent warmup requests.
| Parameter | Type | Description |
|---|---|---|
| $concurrency | int | Concurrent requests |
add_filter('mamba_preload_concurrency', function($c) {
return 5; // Increase for powerful servers
});Define priority product IDs to warm first.
| Parameter | Type | Description |
|---|---|---|
| $product_ids | array | Array of product IDs |
add_filter('mamba_priority_warmup_products', function($ids) {
return wc_get_products([
'limit' => 50,
'orderby' => 'popularity',
'return' => 'ids'
]);
});Define priority category IDs to warm first.
| Parameter | Type | Description |
|---|---|---|
| $category_ids | array | Array of term IDs |
add_filter('mamba_priority_warmup_categories', function($ids) {
return [10, 15, 20]; // Featured categories
});Number of shop pagination pages to warm.
| Parameter | Type | Description |
|---|---|---|
| $pages | int | Number of pages |
add_filter('mamba_warmup_shop_pages', function($pages) {
return 10;
});Define which orderby variants to warm for shop pages.
| Parameter | Type | Description |
|---|---|---|
| $orderbys | array | Array of orderby values |
add_filter('mamba_warmup_shop_orderby', function($orderbys) {
return ['', 'popularity', 'price'];
});Define which attribute taxonomies to warm.
| Parameter | Type | Description |
|---|---|---|
| $taxonomies | array | Array of taxonomy names |
add_filter('mamba_warmup_attribute_taxonomies', function($taxonomies) {
return ['pa_color', 'pa_size'];
});Maximum variants to warm per individual URL.
| Parameter | Type | Description |
|---|---|---|
| $max | int | Maximum per URL |
add_filter('mamba_warmup_max_variants_per_url', function($max) {
return 6;
});Maximum country variants to warm.
| Parameter | Type | Description |
|---|---|---|
| $max | int | Maximum countries |
add_filter('mamba_warmup_max_country_variants', function($max) {
return 5;
});SSL host verification level (0, 1, or 2).
| Parameter | Type | Description |
|---|---|---|
| $level | int | Verification level |
add_filter('mamba_warmup_ssl_verify_host', function($level) {
return 0; // Disable for development
});Filter which endpoint is used for warmup requests.
| Parameter | Type | Description |
|---|---|---|
| $endpoint | string | Endpoint URL |
add_filter('mamba_preload_endpoint_used', function($endpoint) {
return 'https://warmup.example.com/';
});Maximum attribute taxonomies to warm.
| Parameter | Type | Description |
|---|---|---|
| $max | int | Maximum count |
add_filter('mamba_warmup_max_attribute_taxonomies', function($max) {
return 10;
});Maximum terms per attribute taxonomy to warm.
| Parameter | Type | Description |
|---|---|---|
| $max | int | Maximum terms |
add_filter('mamba_warmup_attribute_terms_per_tax', function($max) {
return 20;
});Filter the primary variant combinations for warmup.
| Parameter | Type | Description |
|---|---|---|
| $variants | array | Array of variant combinations |
add_filter('mamba_warmup_primary_variants', function($variants) {
$variants[] = ['device' => 'desktop', 'lang' => 'en', 'currency' => 'USD'];
return $variants;
});Store API
10 filtersControl Store API caching for WooCommerce Blocks.
Customize the TTL for Store API responses.
| Parameter | Type | Description |
|---|---|---|
| $ttl | int | TTL in seconds |
add_filter('mamba_store_api_ttl', function($ttl) {
return 1800; // 30 minutes
});Define URL patterns permitted for Store API caching.
| Parameter | Type | Description |
|---|---|---|
| $patterns | array | Array of regex patterns |
add_filter('mamba_store_api_allow_patterns', function($patterns) {
$patterns[] = '#/wc/store/v1/products#';
return $patterns;
});Define URL patterns to block from Store API caching.
| Parameter | Type | Description |
|---|---|---|
| $patterns | array | Array of regex patterns |
add_filter('mamba_store_api_blocklist', function($patterns) {
$patterns[] = '#/wc/store/v1/cart#';
return $patterns;
});Customize Vary headers for Store API responses.
| Parameter | Type | Description |
|---|---|---|
| $vary | array | Array of Vary header values |
add_filter('mamba_store_api_vary', function($vary) {
$vary[] = 'X-WC-Session';
return $vary;
});Add extra parts to Store API cache keys.
| Parameter | Type | Description |
|---|---|---|
| $parts | array | Array of key parts |
add_filter('mamba_store_api_extra_key_parts', function($parts) {
$parts['custom'] = get_custom_context();
return $parts;
});Define query parameters to strip from Store API cache keys.
| Parameter | Type | Description |
|---|---|---|
| $params | array | Array of parameter names |
add_filter('mamba_store_api_noise_params', function($params) {
$params[] = 'timestamp';
return $params;
});Define Store API endpoints to preload during warmup.
| Parameter | Type | Description |
|---|---|---|
| $endpoints | array | Array of endpoint paths |
add_filter('mamba_store_api_preload_endpoints', function($endpoints) {
$endpoints[] = '/wc/store/v1/products?per_page=12';
return $endpoints;
});Filter Store API URLs for warmup.
| Parameter | Type | Description |
|---|---|---|
| $urls | array | Array of URLs |
add_filter('mamba_warmup_store_api_urls', function($urls) {
$urls[] = home_url('/wp-json/wc/store/v1/products?featured=true');
return $urls;
});Define query parameters that can have multiple values.
| Parameter | Type | Description |
|---|---|---|
| $params | array | Array of parameter names |
add_filter('mamba_store_api_multi_params', function($params) {
$params[] = 'custom_filter';
return $params;
});Define cacheable patterns for Store API warmup.
| Parameter | Type | Description |
|---|---|---|
| $patterns | array | Array of patterns |
add_filter('mamba_warmup_store_api_cacheable_patterns', function($patterns) {
$patterns[] = '#/wc/store/v1/products#';
return $patterns;
});LCP Optimization
11 filtersControl Largest Contentful Paint detection and preload hints.
Whether to output LCP preload hints on the current page.
| Parameter | Type | Description |
|---|---|---|
| $should | bool | Whether to output LCP hints |
add_filter('mamba_lcp_should_output', function($should) {
if (is_page('no-lcp')) {
return false;
}
return $should;
});Maximum number of images to emit preload hints for.
| Parameter | Type | Description |
|---|---|---|
| $max | int | Maximum image preloads |
add_filter('mamba_lcp_max_image_preloads', function($max) {
return 2;
});Image size for the main product image LCP preload hint.
| Parameter | Type | Description |
|---|---|---|
| $size | string | WordPress image size name |
add_filter('mamba_lcp_product_main_size', function($size) {
return 'my_product_hero';
});Minimum width for an image to be considered LCP candidate.
| Parameter | Type | Description |
|---|---|---|
| $width | int | Minimum width in pixels |
add_filter('mamba_lcp_min_first_image_width', function($width) {
return 400;
});Determine if a specific image is critical for LCP.
| Parameter | Type | Description |
|---|---|---|
| $is_critical | bool | Whether image is critical |
| $attachment_id | int | Attachment ID |
add_filter('mamba_lcp_is_critical_image', function($is_critical, $attachment_id) {
if (get_post_meta($attachment_id, '_is_hero', true)) {
return true;
}
return $is_critical;
}, 10, 2);Image size to use for featured image LCP.
| Parameter | Type | Description |
|---|---|---|
| $size | string | Image size name |
add_filter('mamba_lcp_featured_image_size', function($size) {
return 'full';
});Image size for category image LCP.
| Parameter | Type | Description |
|---|---|---|
| $size | string | Image size name |
add_filter('mamba_lcp_category_image_size', function($size) {
return 'medium_large';
});Image size for shop page LCP.
| Parameter | Type | Description |
|---|---|---|
| $size | string | Image size name |
add_filter('mamba_lcp_shop_image_size', function($size) {
return 'medium';
});Filter LCP candidate images.
| Parameter | Type | Description |
|---|---|---|
| $candidates | array | Array of candidate images |
add_filter('mamba_lcp_collect_candidates', function($candidates) {
$candidates[] = [
'url' => 'https://example.com/hero.jpg',
'srcset' => '',
'sizes' => ''
];
return $candidates;
});Whether to push LCP hints from image attributes.
| Parameter | Type | Description |
|---|---|---|
| $push | bool | Whether to push |
| $attachment_id | int | Attachment ID |
| $size | string | Image size |
add_filter('mamba_lcp_push_from_attr', function($push, $id, $size) {
return $size === 'full';
}, 10, 3);Image size for product gallery LCP.
| Parameter | Type | Description |
|---|---|---|
| $size | string | Image size name |
add_filter('mamba_lcp_product_gallery_size', function($size) {
return 'large';
});CDN
5 filtersConfigure CDN integration, geo-targeting, and URL rewriting.
Whether to rewrite CDN URLs in AJAX responses.
| Parameter | Type | Description |
|---|---|---|
| $rewrite | bool | Whether to rewrite |
add_filter('mamba_cdn_rewrite_in_ajax', '__return_true');Define countries used for CDN geo-targeting.
| Parameter | Type | Description |
|---|---|---|
| $countries | array | Array of ISO country codes |
add_filter('mamba_cdn_geo_countries', function($countries) {
return ['US', 'CA', 'GB', 'AU'];
});Maximum countries for CDN geo-targeting.
| Parameter | Type | Description |
|---|---|---|
| $max | int | Maximum count |
add_filter('mamba_cdn_geo_max_countries', function($max) {
return 10;
});Top countries for CDN geo-targeting priority.
| Parameter | Type | Description |
|---|---|---|
| $countries | array | Array of country codes |
add_filter('mamba_cdn_geo_top_countries', function($countries) {
return ['US', 'GB', 'DE'];
});Primary languages for CDN targeting.
| Parameter | Type | Description |
|---|---|---|
| $languages | array | Array of language codes |
add_filter('mamba_cdn_primary_languages', function($languages) {
return ['en', 'de', 'fr'];
});Database Optimization
1 filterControl automatic database cleanup and HPOS meta management.
Enable aggressive HPOS meta cleanup for high-order-volume stores.
| Parameter | Type | Description |
|---|---|---|
| $aggressive | bool | Whether to use aggressive cleanup |
add_filter('mamba_db_hpos_aggressive_meta_cleanup', '__return_true');Miscellaneous
4 filtersAdmin access control, DNS prefetch, hover prefetch, and external images.
Customize the WordPress capability required to access Mamba’s settings.
| Parameter | Type | Description |
|---|---|---|
| $capability | string | Required capability |
add_filter('mamba_admin_capability', function($cap) {
return 'manage_woocommerce';
});Define domains for automatic DNS prefetch hints.
| Parameter | Type | Description |
|---|---|---|
| $domains | array | Array of domain names |
add_filter('mamba_dns_prefetch_auto_domains', function($domains) {
$domains[] = 'cdn.example.com';
return $domains;
});Enable debug mode for hover prefetch.
| Parameter | Type | Description |
|---|---|---|
| $debug | bool | Whether to enable debug |
add_filter('mamba_hover_prefetch_debug', '__return_true');Whether to check dimensions for external images.
| Parameter | Type | Description |
|---|---|---|
| $check | bool | Whether to check |
add_filter('mamba_image_dimensions_check_external', '__return_true');Action Hooks
7 actionsActions fire at key moments in the cache lifecycle. Use them to trigger external cache purges, log events, or notify other systems.
Fired when all caches are purged.
add_action('mamba_purge_all', function() {
my_external_cache_clear();
});Fired when specific URLs are purged.
| Parameter | Type | Description |
|---|---|---|
| $urls | array | Array of purged URLs |
add_action('mamba_purge_urls', function($urls) {
foreach ($urls as $url) {
error_log('Purged: ' . $url);
}
});Fired when cache tags are purged for CDN integration.
| Parameter | Type | Description |
|---|---|---|
| $tags | array | Array of purged cache tags |
add_action('mamba_purge_tags', function($tags) {
my_cdn_purge_tags($tags);
});Fired after any cache purge operation completes.
add_action('mamba_cache_purged', function() {
error_log('Cache purged at ' . current_time('mysql'));
});Fired when a cache error occurs.
| Parameter | Type | Description |
|---|---|---|
| $error | string | Error message |
| $context | array | Error context data |
add_action('mamba_cache_error', function($error, $context) {
error_log('Mamba error: ' . $error);
}, 10, 2);Fired when Store API cache is cleared.
add_action('mamba_store_api_cleared', function() {
wp_remote_post('https://api.example.com/cache-cleared');
});Fired when a database cleanup task completes.
| Parameter | Type | Description |
|---|---|---|
| $task_id | string | Task identifier |
| $rows_affected | int | Rows affected |
add_action('mamba_db_task_completed', function($task_id, $rows) {
error_log("Task {$task_id} cleaned {$rows} rows");
}, 10, 2);WP-CLI Purge Commands
9 commandsCommand-line cache purge operations. All commands use the prefix wp mamba-cache-for-woocommerce.
Purges all page cache entries and related markers.
wp mamba-cache-for-woocommerce purge allPurges only the Store API cache (used by WooCommerce Blocks).
wp mamba-cache-for-woocommerce purge store-apiPurges a specific URL from the cache.
| Argument | Required | Description |
|---|---|---|
| <url> | Yes | Full URL to purge |
| Option | Description |
|---|---|
| –and-warm | Re-warm the URL after purging |
wp mamba-cache-for-woocommerce purge url https://example.com/product/my-product/ --and-warmPurges multiple URLs from a file (one URL per line).
| Argument | Required | Description |
|---|---|---|
| <file> | Yes | Path to file containing URLs |
wp mamba-cache-for-woocommerce purge urls /path/to/urls.txt --and-warmPurges all cache entries related to a specific product.
| Argument | Required | Description |
|---|---|---|
| <id> | Yes | WooCommerce product ID |
wp mamba-cache-for-woocommerce purge product 123Purges cache for a specific product category.
| Argument | Required | Description |
|---|---|---|
| <term_id> | Yes | Product category term ID |
wp mamba-cache-for-woocommerce purge category 45 --and-warmPurges the main WooCommerce shop page cache.
wp mamba-cache-for-woocommerce purge shop --and-warmPurges the homepage cache.
wp mamba-cache-for-woocommerce purge home --and-warmPurges CDN cache by cache tags (for CDN integrations).
| Argument | Required | Description |
|---|---|---|
| <tags> | Yes | Comma-separated list of cache tags |
wp mamba-cache-for-woocommerce purge tags product_123,category_45,store_api_productsWP-CLI Warmup Commands
5 commandsCommand-line cache warmup operations for automation and deployment scripts.
Starts a cache warmup job.
wp mamba-cache-for-woocommerce warmup startChecks the current warmup job status. Returns JSON.
wp mamba-cache-for-woocommerce warmup status{
"status": "running",
"total_urls": 1250,
"completed": 847,
"success": 845,
"failed": 2,
"progress_percent": 67.76
}Cancels a running warmup job.
wp mamba-cache-for-woocommerce warmup cancelResumes a paused warmup job.
wp mamba-cache-for-woocommerce warmup resumeDisplays warmup errors from the current or last job.
wp mamba-cache-for-woocommerce warmup errorsCLI Examples
Common usage patterns and deployment scripts.
#!/bin/bash
set -e
echo "Clearing all cache..."
wp mamba-cache-for-woocommerce purge all
echo "Warming critical pages..."
wp mamba-cache-for-woocommerce purge home --and-warm
wp mamba-cache-for-woocommerce purge shop --and-warm
echo "Starting full warmup..."
wp mamba-cache-for-woocommerce warmup start
echo "Deployment cache refresh complete!"# Run warmup at 3 AM daily
0 3 * * * cd /var/www/html && wp mamba-cache-for-woocommerce warmup start >> /var/log/mamba-warmup.log 2>&1- name: Clear Mamba Cache
run: |
ssh ${{ secrets.SSH_HOST }} "cd /var/www/html && wp mamba-cache-for-woocommerce purge all"
- name: Warm Cache
run: |
ssh ${{ secrets.SSH_HOST }} "cd /var/www/html && wp mamba-cache-for-woocommerce warmup start"REST API Authentication
All endpoints require authentication. Use WordPress Application Passwords for external integrations. Base URL: /wp-json/mamba-wc/v1/
curl -u "username:xxxx xxxx xxxx xxxx xxxx xxxx" \
https://example.com/wp-json/mamba-wc/v1/cache-statusAUTH=$(echo -n "username:application_password" | base64)
curl -H "Authorization: Basic $AUTH" \
https://example.com/wp-json/mamba-wc/v1/cache-statusStatus Endpoints
3 endpointsRetrieve cache status, statistics, and entry counts.
Returns overall cache status, configuration, and statistics.
{
"enabled": true,
"ttl": 7200,
"stats": {
"cache_hits": 15420,
"cache_misses": 2340,
"cache_size": 52428800
}
}Returns detailed performance statistics with calculated metrics.
{
"hits": 15420,
"misses": 2340,
"rate": 87,
"by_type": {
"product": 8500,
"category": 3200,
"shop": 1500
}
}Returns cache entry counts by content type.
{
"counts": {
"products": 450,
"categories": 25,
"tags": 12,
"shop": 5
},
"total": 530
}Purge Endpoint
Purges cache entries based on scope. This is the primary purge endpoint.
Purges cache entries based on scope parameter.
| Field | Type | Description |
|---|---|---|
| scope | string | all, store-api, url, urls, product, category, shop, home, tags |
| value | mixed | Value for scope (URL, ID, array of URLs) |
| and_warm | boolean | Re-warm after purging (optional) |
curl -X POST -u user:pass \
-H "Content-Type: application/json" \
-d '{"scope": "all"}' \
https://example.com/wp-json/mamba-wc/v1/purgecurl -X POST -u user:pass \
-H "Content-Type: application/json" \
-d '{"scope": "product", "value": 123}' \
https://example.com/wp-json/mamba-wc/v1/purgeWarmup Endpoints
4 endpointsControl cache warmup operations via REST API.
Starts a foreground warmup job.
curl -X POST -u user:pass https://example.com/wp-json/mamba-wc/v1/warmupReturns current warmup job status.
{
"status": "running",
"total_urls": 1250,
"completed": 847,
"progress_percent": 67.76
}Cancels a running warmup job.
curl -X POST -u user:pass https://example.com/wp-json/mamba-wc/v1/warmup-cancelReturns errors from the current or last warmup job.
{
"errors": [
{
"url": "https://example.com/product/broken/",
"error": "HTTP 404"
}
],
"stats": {"total_errors": 2, "error_rate": 0.16}
}API Examples
Common integration patterns and code samples.
const auth = btoa('username:app_password');
async function purgeAll() {
const response = await fetch(
'https://example.com/wp-json/mamba-wc/v1/purge',
{
method: 'POST',
headers: {
'Authorization': `Basic ${auth}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({ scope: 'all' })
}
);
return response.json();
}#!/bin/bash
API_URL="https://example.com/wp-json/mamba-wc/v1"
AUTH="username:application_password"
# Clear all cache
curl -X POST -u "$AUTH" \
-H "Content-Type: application/json" \
-d '{"scope": "all"}' \
"$API_URL/purge"
# Start warmup
curl -X POST -u "$AUTH" "$API_URL/warmup"Best Practices
Follow these conventions to ensure hooks work reliably and perform well.
- 1Always return a value. Filters must return the modified value even if unchanged.
- 2Return the correct type. Filters must return the same type they receive.
- 3Use the correct argument count. Declare the correct parameter count in add_filter().
- 4Use early returns. Check conditions at the top and return early.
- 5Cache expensive operations. Use static variables for DB queries or remote requests.
- 6Use default priority (10). Only set custom priority when explicitly needed.
add_filter('mamba_warmup_filtered_urls', function($urls) {
// Early return if nothing to filter
if (empty($urls)) {
return $urls;
}
// Cache expensive DB lookup
static $excluded = null;
if ($excluded === null) {
$excluded = get_option('my_excluded_urls', []);
}
// Return same type (array)
return array_filter($urls, function($url) use ($excluded) {
return !in_array($url, $excluded, true);
});
}, 10, 1);