Store API cache

mamba_store_api_vary
Adjust the list of Vary headers for GET Store API responses. Use this to balance correctness against cache HIT rates.

add_filter('mamba_store_api_vary', fn($vary) => ['Accept-Language', 'Accept-Encoding']);

mamba_store_api_allow_patterns
Extend the allow-list of cacheable Store API route patterns (regex).

add_filter('mamba_store_api_allow_patterns', function ($patterns) {
    $patterns[] = '#^/products/attributes$#';
    return $patterns;
});

mamba_store_api_blocklist
Extend the block-list of user-scoped Store API route prefixes that must never be cached.

add_filter('mamba_store_api_blocklist', function ($blocked) {
    $blocked[] = '/user';
    return $blocked;
});

mamba_store_api_multi_params
Treat certain scalar parameters as arrays for cache key normalization.

add_filter('mamba_store_api_multi_params', function ($keys) {
    $keys[] = 'rating';
    return $keys;
});

mamba_store_api_noise_params
Remove tracking or noise parameters from Store API cache keys.

add_filter('mamba_store_api_noise_params', function ($params) {
    return array_merge($params, ['fbclid', 'gclid', 'msclkid', 'ref']);
});

mamba_store_api_extra_key_parts
Add custom variance parts to the Store API cache key (e.g., membership tier).

add_filter('mamba_store_api_extra_key_parts', function ($parts) {
    if (is_user_logged_in() && current_user_can('b2b_gold')) {
        $parts[] = 'tier=gold';
    }
    return $parts;
});

mamba_store_api_preload_endpoints
Modify the set of Store API endpoints preloaded for improved UX responsiveness.

add_filter('mamba_store_api_preload_endpoints', function ($endpoints) {
    $endpoints[] = '/wc/store/v1/products?orderby=popularity';
    return $endpoints;
});

mamba_preload_endpoint_used
Decide case-by-case whether a discovered preload endpoint should be used.

add_filter('mamba_preload_endpoint_used', function ($use, $endpoint) {
    // Skip page 2 from preloading
    return (strpos($endpoint, 'page=2') === false);
}, 10, 2);

Copyright 2025 - Mamba


Mamba mascot