Developer Reference

Filters & Actions Reference – Mamba Cache for WooCommerce
Complete Technical Documentation

Developer Reference

Comprehensive reference for all developer APIs in Mamba Cache for WooCommerce — including 70+ filters & actions, WP-CLI commands, and REST API endpoints.

Last updated: February 2026 Document version 1.0.0
70+
Filter hooks
14
CLI commands
8
API endpoints
7
Action hooks

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 filters

Control cache TTL, size limits, headers, cookies, and query parameter handling.

mamba_cache_ttl_for_requestFilter

Customize the cache TTL (time-to-live) for specific requests. Useful for giving shorter or longer cache lifetimes to particular URL patterns.

Default86400 (24 hours)
Parameters
ParameterTypeDescription
$ttlintDefault TTL in seconds
$request_uristringCurrent request URI
PHP
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);
mamba_browser_ttlFilter

Customize the browser cache TTL sent in Cache-Control headers to the client.

Parameters
ParameterTypeDescription
$ttlintBrowser TTL in seconds
PHP
add_filter('mamba_browser_ttl', function($ttl) {
    return 300; // 5-minute browser cache
});
mamba_cache_size_limitFilter

Set the maximum cache size in bytes before automatic cleanup is triggered.

Default1073741824 (1 GB)
Parameters
ParameterTypeDescription
$limitintSize limit in bytes
PHP
add_filter('mamba_cache_size_limit', function($limit) {
    return 500 * 1024 * 1024; // 500 MB
});
mamba_cache_stale_lock_windowFilter

Set the stale-while-revalidate window in seconds.

Default60
Parameters
ParameterTypeDescription
$windowintLock window in seconds
PHP
add_filter('mamba_cache_stale_lock_window', function($window) {
    return 300; // 5 minutes
});
mamba_cache_default_cache_controlFilter

Customize the default Cache-Control header value.

Parameters
ParameterTypeDescription
$headerstringCache-Control header value
PHP
add_filter('mamba_cache_default_cache_control', function($header) {
    return 'public, max-age=3600, s-maxage=86400';
});
mamba_cache_header_whitelistFilter

Define which response headers should be cached alongside the page content.

Default[‘Content-Type’, ‘X-Robots-Tag’, ‘Link’]
Parameters
ParameterTypeDescription
$headersarrayArray of header names
PHP
add_filter('mamba_cache_header_whitelist', function($headers) {
    $headers[] = 'X-Custom-Header';
    return $headers;
});
mamba_cache_block_on_cookiesFilter

Define cookies that prevent caching when present.

DefaultWooCommerce cart/session cookies
Parameters
ParameterTypeDescription
$cookiesarrayArray of cookie name patterns
PHP
add_filter('mamba_cache_block_on_cookies', function($cookies) {
    $cookies[] = 'my_custom_session';
    return $cookies;
});
mamba_cacheable_query_paramsFilter

Define which query parameters should be included in cache keys.

Defaultorderby, order, per_page, page, paged, min_price, max_price, etc.
Parameters
ParameterTypeDescription
$paramsarrayArray of parameter names
PHP
add_filter('mamba_cacheable_query_params', function($params) {
    $params[] = 'custom_filter';
    return $params;
});
mamba_tracking_paramsFilter

Define tracking parameters to strip from cache keys.

DefaultUTM parameters, fbclid, gclid, etc.
Parameters
ParameterTypeDescription
$paramsarrayArray of tracking parameter names
PHP
add_filter('mamba_tracking_params', function($params) {
    $params[] = 'my_tracking_id';
    return $params;
});
mamba_cache_honor_client_no_cacheFilter

Whether to honor client Cache-Control: no-cache requests.

Defaultfalse
Parameters
ParameterTypeDescription
$honorboolWhether to honor no-cache
PHP
add_filter('mamba_cache_honor_client_no_cache', '__return_true');
mamba_cache_send_content_length_on_hitFilter

Whether to send Content-Length header on cache hits.

Defaulttrue
Parameters
ParameterTypeDescription
$sendboolWhether to send header
PHP
add_filter('mamba_cache_send_content_length_on_hit', '__return_false');

Cache Variants

5 filters

Control how separate cache entries are created based on language, currency, country, and user role.

mamba_cache_varyFilter

Customize the Vary header used to differentiate cache variants.

Parameters
ParameterTypeDescription
$varyarrayArray of Vary header values
PHP
add_filter('mamba_cache_vary', function($vary) {
    $vary[] = 'X-Custom-Header';
    return $vary;
});
mamba_variant_langFilter

Customize the language variant used in cache keys.

Parameters
ParameterTypeDescription
$langstring|nullCurrent language code
PHP
add_filter('mamba_variant_lang', function($lang) {
    if (isset($_COOKIE['user_lang'])) {
        return sanitize_key($_COOKIE['user_lang']);
    }
    return $lang;
});
mamba_variant_currencyFilter

Customize the currency variant used in cache keys.

Parameters
ParameterTypeDescription
$currencystring|nullCurrent currency code
PHP
add_filter('mamba_variant_currency', function($currency) {
    return get_woocommerce_currency();
});
mamba_variant_countryFilter

Customize the country variant for cache keys.

Parameters
ParameterTypeDescription
$countrystring|nullCurrent country code
PHP
add_filter('mamba_variant_country', function($country) {
    return my_get_user_country();
});
mamba_role_based_pricing_dimensionsFilter

Define additional cache dimensions for role-based pricing plugins.

Parameters
ParameterTypeDescription
$dimensionsarrayArray of dimension values
PHP
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 filters

Control the scope of cache clearing when content changes.

mamba_archive_clear_pagesFilter

Customize how many pagination pages to clear when invalidating archives.

Default5
Parameters
ParameterTypeDescription
$pagesintNumber of pages to clear
PHP
add_filter('mamba_archive_clear_pages', function($pages) {
    return 10;
});
mamba_shop_clear_pagesFilter

Customize how many shop pagination pages to clear.

Default5
Parameters
ParameterTypeDescription
$pagesintNumber of pages to clear
PHP
add_filter('mamba_shop_clear_pages', function($pages) {
    return 20;
});
mamba_shop_clear_orderbyFilter

Define which orderby variants to clear when invalidating shop pages.

Default”, ‘menu_order’, ‘popularity’, ‘rating’, ‘date’, ‘price’, ‘price-desc’
Parameters
ParameterTypeDescription
$orderbysarrayArray of orderby values
PHP
add_filter('mamba_shop_clear_orderby', function($orderbys) {
    $orderbys[] = 'custom_sort';
    return $orderbys;
});

Warmup & Preloading

21 filters

Control cache warming behavior — URLs, concurrency, device variants, SSL settings, and priority.

mamba_warmup_max_urlsFilter

Maximum number of URLs to include in a single warmup job.

Default5000
Parameters
ParameterTypeDescription
$maxintMaximum URL count
PHP
add_filter('mamba_warmup_max_urls', function($max) {
    return 1000;
});
mamba_warmup_devicesFilter

Define which device types to warm.

Default[‘desktop’, ‘mobile’, ‘tablet’]
Parameters
ParameterTypeDescription
$devicesarrayArray of device types
PHP
add_filter('mamba_warmup_devices', function($devices) {
    return ['desktop', 'mobile'];
});
mamba_warmup_countriesFilter

Define which countries to warm for geo-variant caching.

Parameters
ParameterTypeDescription
$countriesarrayArray of country codes
PHP
add_filter('mamba_warmup_countries', function($countries) {
    return ['US', 'GB', 'DE', 'FR'];
});
mamba_warmup_exclude_outofstockFilter

Whether to exclude out-of-stock products from warmup.

Defaultfalse
Parameters
ParameterTypeDescription
$excludeboolWhether to exclude
PHP
add_filter('mamba_warmup_exclude_outofstock', '__return_true');
mamba_warmup_filtered_urlsFilter

Filter the final list of URLs before warmup begins.

Parameters
ParameterTypeDescription
$urlsarrayArray of URLs to warm
PHP
add_filter('mamba_warmup_filtered_urls', function($urls) {
    return array_filter($urls, function($url) {
        return strpos($url, '/private/') === false;
    });
});
mamba_warmup_ssl_verifyFilter

Whether to verify SSL certificates during warmup requests.

Defaulttrue (false in WP_DEBUG)
Parameters
ParameterTypeDescription
$verifyboolWhether to verify SSL
PHP
add_filter('mamba_warmup_ssl_verify', '__return_false');
mamba_warmup_max_variantsFilter

Maximum number of variants (device/language/currency) per URL.

Default3
Parameters
ParameterTypeDescription
$maxintMaximum variants
PHP
add_filter('mamba_warmup_max_variants', function($max) {
    return 5; // More variants for multilingual sites
});
mamba_warmup_max_execution_timeFilter

Maximum execution time for warmup jobs in seconds.

Default600 (10 minutes)
Parameters
ParameterTypeDescription
$timeintMax time in seconds
PHP
add_filter('mamba_warmup_max_execution_time', function($time) {
    return 1800; // 30 minutes
});
mamba_preload_concurrencyFilter

Number of concurrent warmup requests.

Default3
Parameters
ParameterTypeDescription
$concurrencyintConcurrent requests
PHP
add_filter('mamba_preload_concurrency', function($c) {
    return 5; // Increase for powerful servers
});
mamba_priority_warmup_productsFilter

Define priority product IDs to warm first.

Parameters
ParameterTypeDescription
$product_idsarrayArray of product IDs
PHP
add_filter('mamba_priority_warmup_products', function($ids) {
    return wc_get_products([
        'limit' => 50,
        'orderby' => 'popularity',
        'return' => 'ids'
    ]);
});
mamba_priority_warmup_categoriesFilter

Define priority category IDs to warm first.

Parameters
ParameterTypeDescription
$category_idsarrayArray of term IDs
PHP
add_filter('mamba_priority_warmup_categories', function($ids) {
    return [10, 15, 20]; // Featured categories
});
mamba_warmup_shop_pagesFilter

Number of shop pagination pages to warm.

Default5
Parameters
ParameterTypeDescription
$pagesintNumber of pages
PHP
add_filter('mamba_warmup_shop_pages', function($pages) {
    return 10;
});
mamba_warmup_shop_orderbyFilter

Define which orderby variants to warm for shop pages.

Parameters
ParameterTypeDescription
$orderbysarrayArray of orderby values
PHP
add_filter('mamba_warmup_shop_orderby', function($orderbys) {
    return ['', 'popularity', 'price'];
});
mamba_warmup_attribute_taxonomiesFilter

Define which attribute taxonomies to warm.

Parameters
ParameterTypeDescription
$taxonomiesarrayArray of taxonomy names
PHP
add_filter('mamba_warmup_attribute_taxonomies', function($taxonomies) {
    return ['pa_color', 'pa_size'];
});
mamba_warmup_max_variants_per_urlFilter

Maximum variants to warm per individual URL.

Default3
Parameters
ParameterTypeDescription
$maxintMaximum per URL
PHP
add_filter('mamba_warmup_max_variants_per_url', function($max) {
    return 6;
});
mamba_warmup_max_country_variantsFilter

Maximum country variants to warm.

Default3
Parameters
ParameterTypeDescription
$maxintMaximum countries
PHP
add_filter('mamba_warmup_max_country_variants', function($max) {
    return 5;
});
mamba_warmup_ssl_verify_hostFilter

SSL host verification level (0, 1, or 2).

Default2 (strict)
Parameters
ParameterTypeDescription
$levelintVerification level
PHP
add_filter('mamba_warmup_ssl_verify_host', function($level) {
    return 0; // Disable for development
});
mamba_preload_endpoint_usedFilter

Filter which endpoint is used for warmup requests.

Parameters
ParameterTypeDescription
$endpointstringEndpoint URL
PHP
add_filter('mamba_preload_endpoint_used', function($endpoint) {
    return 'https://warmup.example.com/';
});
mamba_warmup_max_attribute_taxonomiesFilter

Maximum attribute taxonomies to warm.

Default5
Parameters
ParameterTypeDescription
$maxintMaximum count
PHP
add_filter('mamba_warmup_max_attribute_taxonomies', function($max) {
    return 10;
});
mamba_warmup_attribute_terms_per_taxFilter

Maximum terms per attribute taxonomy to warm.

Default10
Parameters
ParameterTypeDescription
$maxintMaximum terms
PHP
add_filter('mamba_warmup_attribute_terms_per_tax', function($max) {
    return 20;
});
mamba_warmup_primary_variantsFilter

Filter the primary variant combinations for warmup.

Parameters
ParameterTypeDescription
$variantsarrayArray of variant combinations
PHP
add_filter('mamba_warmup_primary_variants', function($variants) {
    $variants[] = ['device' => 'desktop', 'lang' => 'en', 'currency' => 'USD'];
    return $variants;
});

Store API

10 filters

Control Store API caching for WooCommerce Blocks.

mamba_store_api_ttlFilter

Customize the TTL for Store API responses.

Default3600 (1 hour)
Parameters
ParameterTypeDescription
$ttlintTTL in seconds
PHP
add_filter('mamba_store_api_ttl', function($ttl) {
    return 1800; // 30 minutes
});
mamba_store_api_allow_patternsFilter

Define URL patterns permitted for Store API caching.

Parameters
ParameterTypeDescription
$patternsarrayArray of regex patterns
PHP
add_filter('mamba_store_api_allow_patterns', function($patterns) {
    $patterns[] = '#/wc/store/v1/products#';
    return $patterns;
});
mamba_store_api_blocklistFilter

Define URL patterns to block from Store API caching.

Parameters
ParameterTypeDescription
$patternsarrayArray of regex patterns
PHP
add_filter('mamba_store_api_blocklist', function($patterns) {
    $patterns[] = '#/wc/store/v1/cart#';
    return $patterns;
});
mamba_store_api_varyFilter

Customize Vary headers for Store API responses.

Parameters
ParameterTypeDescription
$varyarrayArray of Vary header values
PHP
add_filter('mamba_store_api_vary', function($vary) {
    $vary[] = 'X-WC-Session';
    return $vary;
});
mamba_store_api_extra_key_partsFilter

Add extra parts to Store API cache keys.

Parameters
ParameterTypeDescription
$partsarrayArray of key parts
PHP
add_filter('mamba_store_api_extra_key_parts', function($parts) {
    $parts['custom'] = get_custom_context();
    return $parts;
});
mamba_store_api_noise_paramsFilter

Define query parameters to strip from Store API cache keys.

Parameters
ParameterTypeDescription
$paramsarrayArray of parameter names
PHP
add_filter('mamba_store_api_noise_params', function($params) {
    $params[] = 'timestamp';
    return $params;
});
mamba_store_api_preload_endpointsFilter

Define Store API endpoints to preload during warmup.

Parameters
ParameterTypeDescription
$endpointsarrayArray of endpoint paths
PHP
add_filter('mamba_store_api_preload_endpoints', function($endpoints) {
    $endpoints[] = '/wc/store/v1/products?per_page=12';
    return $endpoints;
});
mamba_warmup_store_api_urlsFilter

Filter Store API URLs for warmup.

Parameters
ParameterTypeDescription
$urlsarrayArray of URLs
PHP
add_filter('mamba_warmup_store_api_urls', function($urls) {
    $urls[] = home_url('/wp-json/wc/store/v1/products?featured=true');
    return $urls;
});
mamba_store_api_multi_paramsFilter

Define query parameters that can have multiple values.

Parameters
ParameterTypeDescription
$paramsarrayArray of parameter names
PHP
add_filter('mamba_store_api_multi_params', function($params) {
    $params[] = 'custom_filter';
    return $params;
});
mamba_warmup_store_api_cacheable_patternsFilter

Define cacheable patterns for Store API warmup.

Parameters
ParameterTypeDescription
$patternsarrayArray of patterns
PHP
add_filter('mamba_warmup_store_api_cacheable_patterns', function($patterns) {
    $patterns[] = '#/wc/store/v1/products#';
    return $patterns;
});

LCP Optimization

11 filters

Control Largest Contentful Paint detection and preload hints.

mamba_lcp_should_outputFilter

Whether to output LCP preload hints on the current page.

Parameters
ParameterTypeDescription
$shouldboolWhether to output LCP hints
PHP
add_filter('mamba_lcp_should_output', function($should) {
    if (is_page('no-lcp')) {
        return false;
    }
    return $should;
});
mamba_lcp_max_image_preloadsFilter

Maximum number of images to emit preload hints for.

Default1
Parameters
ParameterTypeDescription
$maxintMaximum image preloads
PHP
add_filter('mamba_lcp_max_image_preloads', function($max) {
    return 2;
});
mamba_lcp_product_main_sizeFilter

Image size for the main product image LCP preload hint.

Default‘woocommerce_single’
Parameters
ParameterTypeDescription
$sizestringWordPress image size name
PHP
add_filter('mamba_lcp_product_main_size', function($size) {
    return 'my_product_hero';
});
mamba_lcp_min_first_image_widthFilter

Minimum width for an image to be considered LCP candidate.

Default320
Parameters
ParameterTypeDescription
$widthintMinimum width in pixels
PHP
add_filter('mamba_lcp_min_first_image_width', function($width) {
    return 400;
});
mamba_lcp_is_critical_imageFilter

Determine if a specific image is critical for LCP.

Parameters
ParameterTypeDescription
$is_criticalboolWhether image is critical
$attachment_idintAttachment ID
PHP
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);
mamba_lcp_featured_image_sizeFilter

Image size to use for featured image LCP.

Default‘large’
Parameters
ParameterTypeDescription
$sizestringImage size name
PHP
add_filter('mamba_lcp_featured_image_size', function($size) {
    return 'full';
});
mamba_lcp_category_image_sizeFilter

Image size for category image LCP.

Default‘woocommerce_thumbnail’
Parameters
ParameterTypeDescription
$sizestringImage size name
PHP
add_filter('mamba_lcp_category_image_size', function($size) {
    return 'medium_large';
});
mamba_lcp_shop_image_sizeFilter

Image size for shop page LCP.

Default‘woocommerce_thumbnail’
Parameters
ParameterTypeDescription
$sizestringImage size name
PHP
add_filter('mamba_lcp_shop_image_size', function($size) {
    return 'medium';
});
mamba_lcp_collect_candidatesFilter

Filter LCP candidate images.

Parameters
ParameterTypeDescription
$candidatesarrayArray of candidate images
PHP
add_filter('mamba_lcp_collect_candidates', function($candidates) {
    $candidates[] = [
        'url' => 'https://example.com/hero.jpg',
        'srcset' => '',
        'sizes' => ''
    ];
    return $candidates;
});
mamba_lcp_push_from_attrFilter

Whether to push LCP hints from image attributes.

Defaultfalse
Parameters
ParameterTypeDescription
$pushboolWhether to push
$attachment_idintAttachment ID
$sizestringImage size
PHP
add_filter('mamba_lcp_push_from_attr', function($push, $id, $size) {
    return $size === 'full';
}, 10, 3);
mamba_lcp_product_gallery_sizeFilter

Image size for product gallery LCP.

Default‘woocommerce_single’
Parameters
ParameterTypeDescription
$sizestringImage size name
PHP
add_filter('mamba_lcp_product_gallery_size', function($size) {
    return 'large';
});

CDN

5 filters

Configure CDN integration, geo-targeting, and URL rewriting.

mamba_cdn_rewrite_in_ajaxFilter

Whether to rewrite CDN URLs in AJAX responses.

Defaultfalse
Parameters
ParameterTypeDescription
$rewriteboolWhether to rewrite
PHP
add_filter('mamba_cdn_rewrite_in_ajax', '__return_true');
mamba_cdn_geo_countriesFilter

Define countries used for CDN geo-targeting.

Parameters
ParameterTypeDescription
$countriesarrayArray of ISO country codes
PHP
add_filter('mamba_cdn_geo_countries', function($countries) {
    return ['US', 'CA', 'GB', 'AU'];
});
mamba_cdn_geo_max_countriesFilter

Maximum countries for CDN geo-targeting.

Parameters
ParameterTypeDescription
$maxintMaximum count
PHP
add_filter('mamba_cdn_geo_max_countries', function($max) {
    return 10;
});
mamba_cdn_geo_top_countriesFilter

Top countries for CDN geo-targeting priority.

Parameters
ParameterTypeDescription
$countriesarrayArray of country codes
PHP
add_filter('mamba_cdn_geo_top_countries', function($countries) {
    return ['US', 'GB', 'DE'];
});
mamba_cdn_primary_languagesFilter

Primary languages for CDN targeting.

Parameters
ParameterTypeDescription
$languagesarrayArray of language codes
PHP
add_filter('mamba_cdn_primary_languages', function($languages) {
    return ['en', 'de', 'fr'];
});

Database Optimization

1 filter

Control automatic database cleanup and HPOS meta management.

mamba_db_hpos_aggressive_meta_cleanupFilter

Enable aggressive HPOS meta cleanup for high-order-volume stores.

Defaultfalse
Parameters
ParameterTypeDescription
$aggressiveboolWhether to use aggressive cleanup
PHP
add_filter('mamba_db_hpos_aggressive_meta_cleanup', '__return_true');

Miscellaneous

4 filters

Admin access control, DNS prefetch, hover prefetch, and external images.

mamba_admin_capabilityFilter

Customize the WordPress capability required to access Mamba’s settings.

Default‘manage_options’
Parameters
ParameterTypeDescription
$capabilitystringRequired capability
PHP
add_filter('mamba_admin_capability', function($cap) {
    return 'manage_woocommerce';
});
mamba_dns_prefetch_auto_domainsFilter

Define domains for automatic DNS prefetch hints.

Parameters
ParameterTypeDescription
$domainsarrayArray of domain names
PHP
add_filter('mamba_dns_prefetch_auto_domains', function($domains) {
    $domains[] = 'cdn.example.com';
    return $domains;
});
mamba_hover_prefetch_debugFilter

Enable debug mode for hover prefetch.

Defaultfalse
Parameters
ParameterTypeDescription
$debugboolWhether to enable debug
PHP
add_filter('mamba_hover_prefetch_debug', '__return_true');
mamba_image_dimensions_check_externalFilter

Whether to check dimensions for external images.

Defaultfalse
Parameters
ParameterTypeDescription
$checkboolWhether to check
PHP
add_filter('mamba_image_dimensions_check_external', '__return_true');

Action Hooks

7 actions

Actions fire at key moments in the cache lifecycle. Use them to trigger external cache purges, log events, or notify other systems.

mamba_purge_allAction

Fired when all caches are purged.

PHP
add_action('mamba_purge_all', function() {
    my_external_cache_clear();
});
mamba_purge_urlsAction

Fired when specific URLs are purged.

Parameters
ParameterTypeDescription
$urlsarrayArray of purged URLs
PHP
add_action('mamba_purge_urls', function($urls) {
    foreach ($urls as $url) {
        error_log('Purged: ' . $url);
    }
});
mamba_purge_tagsAction

Fired when cache tags are purged for CDN integration.

Parameters
ParameterTypeDescription
$tagsarrayArray of purged cache tags
PHP
add_action('mamba_purge_tags', function($tags) {
    my_cdn_purge_tags($tags);
});
mamba_cache_purgedAction

Fired after any cache purge operation completes.

PHP
add_action('mamba_cache_purged', function() {
    error_log('Cache purged at ' . current_time('mysql'));
});
mamba_cache_errorAction

Fired when a cache error occurs.

Parameters
ParameterTypeDescription
$errorstringError message
$contextarrayError context data
PHP
add_action('mamba_cache_error', function($error, $context) {
    error_log('Mamba error: ' . $error);
}, 10, 2);
mamba_store_api_clearedAction

Fired when Store API cache is cleared.

PHP
add_action('mamba_store_api_cleared', function() {
    wp_remote_post('https://api.example.com/cache-cleared');
});
mamba_db_task_completedAction

Fired when a database cleanup task completes.

Parameters
ParameterTypeDescription
$task_idstringTask identifier
$rows_affectedintRows affected
PHP
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 commands

Command-line cache purge operations. All commands use the prefix wp mamba-cache-for-woocommerce.

purge allCommand

Purges all page cache entries and related markers.

Bash
wp mamba-cache-for-woocommerce purge all
purge store-apiCommand

Purges only the Store API cache (used by WooCommerce Blocks).

Bash
wp mamba-cache-for-woocommerce purge store-api
purge urlCommand

Purges a specific URL from the cache.

Arguments
ArgumentRequiredDescription
<url>YesFull URL to purge
Options
OptionDescription
–and-warmRe-warm the URL after purging
Bash
wp mamba-cache-for-woocommerce purge url https://example.com/product/my-product/ --and-warm
purge urlsCommand

Purges multiple URLs from a file (one URL per line).

Arguments
ArgumentRequiredDescription
<file>YesPath to file containing URLs
Bash
wp mamba-cache-for-woocommerce purge urls /path/to/urls.txt --and-warm
purge productCommand

Purges all cache entries related to a specific product.

Arguments
ArgumentRequiredDescription
<id>YesWooCommerce product ID
Bash
wp mamba-cache-for-woocommerce purge product 123
purge categoryCommand

Purges cache for a specific product category.

Arguments
ArgumentRequiredDescription
<term_id>YesProduct category term ID
Bash
wp mamba-cache-for-woocommerce purge category 45 --and-warm
purge shopCommand

Purges the main WooCommerce shop page cache.

Bash
wp mamba-cache-for-woocommerce purge shop --and-warm
purge homeCommand

Purges the homepage cache.

Bash
wp mamba-cache-for-woocommerce purge home --and-warm
purge tagsCommand

Purges CDN cache by cache tags (for CDN integrations).

Arguments
ArgumentRequiredDescription
<tags>YesComma-separated list of cache tags
Bash
wp mamba-cache-for-woocommerce purge tags product_123,category_45,store_api_products

WP-CLI Warmup Commands

5 commands

Command-line cache warmup operations for automation and deployment scripts.

warmup startCommand

Starts a cache warmup job.

Bash
wp mamba-cache-for-woocommerce warmup start
warmup statusCommand

Checks the current warmup job status. Returns JSON.

Bash
wp mamba-cache-for-woocommerce warmup status
Output
JSON
{
  "status": "running",
  "total_urls": 1250,
  "completed": 847,
  "success": 845,
  "failed": 2,
  "progress_percent": 67.76
}
warmup cancelCommand

Cancels a running warmup job.

Bash
wp mamba-cache-for-woocommerce warmup cancel
warmup resumeCommand

Resumes a paused warmup job.

Bash
wp mamba-cache-for-woocommerce warmup resume
warmup errorsCommand

Displays warmup errors from the current or last job.

Bash
wp mamba-cache-for-woocommerce warmup errors

CLI Examples

Common usage patterns and deployment scripts.

Deployment Script
Bash
#!/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!"
Cron Job (Nightly Warmup)
Crontab
# 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
GitHub Actions
YAML
- 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/

Application Passwords (Recommended)
Bash
curl -u "username:xxxx xxxx xxxx xxxx xxxx xxxx" \
  https://example.com/wp-json/mamba-wc/v1/cache-status
Base64 Authorization Header
Bash
AUTH=$(echo -n "username:application_password" | base64)

curl -H "Authorization: Basic $AUTH" \
  https://example.com/wp-json/mamba-wc/v1/cache-status

Status Endpoints

3 endpoints

Retrieve cache status, statistics, and entry counts.

GET /cache-statusEndpoint

Returns overall cache status, configuration, and statistics.

Response
{
  "enabled": true,
  "ttl": 7200,
  "stats": {
    "cache_hits": 15420,
    "cache_misses": 2340,
    "cache_size": 52428800
  }
}
GET /statsEndpoint

Returns detailed performance statistics with calculated metrics.

Response
{
  "hits": 15420,
  "misses": 2340,
  "rate": 87,
  "by_type": {
    "product": 8500,
    "category": 3200,
    "shop": 1500
  }
}
GET /cache-countsEndpoint

Returns cache entry counts by content type.

Response
{
  "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.

POST /purgeEndpoint

Purges cache entries based on scope parameter.

Request Body
FieldTypeDescription
scopestringall, store-api, url, urls, product, category, shop, home, tags
valuemixedValue for scope (URL, ID, array of URLs)
and_warmbooleanRe-warm after purging (optional)
Purge All
Bash
curl -X POST -u user:pass \
  -H "Content-Type: application/json" \
  -d '{"scope": "all"}' \
  https://example.com/wp-json/mamba-wc/v1/purge
Purge Product
Bash
curl -X POST -u user:pass \
  -H "Content-Type: application/json" \
  -d '{"scope": "product", "value": 123}' \
  https://example.com/wp-json/mamba-wc/v1/purge

Warmup Endpoints

4 endpoints

Control cache warmup operations via REST API.

POST /warmupEndpoint

Starts a foreground warmup job.

Bash
curl -X POST -u user:pass https://example.com/wp-json/mamba-wc/v1/warmup
GET /warmup-statusEndpoint

Returns current warmup job status.

Response
{
  "status": "running",
  "total_urls": 1250,
  "completed": 847,
  "progress_percent": 67.76
}
POST /warmup-cancelEndpoint

Cancels a running warmup job.

Bash
curl -X POST -u user:pass https://example.com/wp-json/mamba-wc/v1/warmup-cancel
GET /warmup-errorsEndpoint

Returns errors from the current or last warmup job.

Response
{
  "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.

JavaScript Client
JavaScript
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();
}
Deployment Webhook (Bash)
Bash
#!/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.
Example — efficient filter using all best practices
PHP
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);