Multisite

MilliCache fully supports WordPress Multisite with per-site cache isolation, network-wide management, and multi-network compatibility.

Installation#Copied!

Network Activation#Copied!

  1. Install MilliCache as a regular plugin
  2. Network-activate from Network Admin → Plugins
  3. Add WP_CACHE to wp-config.php:
 1define( 'WP_CACHE', true );
Important: MilliCache must be network-activated. Per-site activation is not supported in multisite.

Cache Isolation#Copied!

Each site's cache is automatically isolated using flag prefixes:

Environment Flag Format Example
Single site {flag} post:123
Multisite {site_id}:{flag} 2:post:123
Multi-network {network_id}:{site_id}:{flag} 1:2:post:123

This ensures:

  • Site A's cache doesn't affect Site B
  • Clearing Site A doesn't clear Site B
  • Each site can have different content for the same path

Network-Wide Settings#Copied!

Via Constants#Copied!

Settings in wp-config.php apply to all sites:

 1define( 'MC_CACHE_TTL', 86400 );
 2define( 'MC_STORAGE_HOST', 'redis.example.com' );

Via Database#Copied!

Network-level settings are stored in the main site's options. Per-site settings can be configured via the admin UI on each site.

The settings are synced to config files for each site:

/wp-content/settings/millicache/
├── example_com.php
├── site1_example_com.php
└── site2_example_com.php

Each file returns settings for that domain:

 1<?php
 2// example_com.php
 3return [
 4    // ...
 5    'cache' => [
 6        // ...
 7        'ttl' => 3600,  // 1 hour for this site
 8    ],
 9];

Cache Clearing#Copied!

Clear Single Site#Copied!

From a specific site's context:

 1# Clear current site
 2wp millicache clear --url=site1.example.com
 3
 4# Clear by site ID
 5wp millicache clear --site=2

Via admin bar on each site: MilliCache → Clear Site Cache

Clear Multiple Sites#Copied!

 1# Clear specific sites
 2wp millicache clear --site=1,2,3
 3
 4# Clear sites with specific network
 5wp millicache clear --site=1,2,3 --network=1

Clear Entire Network#Copied!

 1# Clear all sites in network
 2wp millicache clear --network=1
 3
 4# Clear all networks
 5wp millicache clear --network=1,2

Via Network Admin bar: MilliCache → Clear Network Cache

Clear All Sites#Copied!

 1wp millicache clear

Without arguments from the main site context, clears all cache.

PHP Functions in Multisite#Copied!

Clear by Site IDs#Copied!

 1// Clear specific sites
 2millicache_clear_cache_by_site_ids( [ 1, 2, 3 ] );
 3
 4// Clear sites in a specific network
 5millicache_clear_cache_by_site_ids( [ 1, 2 ], 1 );
 6
 7// Expire instead of delete
 8millicache_clear_cache_by_site_ids( [ 1, 2 ], null, true );

Clear by Network#Copied!

 1// Clear the entire network
 2millicache_clear_cache_by_network_id( 1 );
 3
 4// Expire instead of delete
 5millicache_clear_cache_by_network_id( 1, true );

Prefix Flags#Copied!

 1$flags = [ 'post:123', 'home' ];
 2
 3// Prefix for current site
 4$prefixed = millicache_prefix_flags( $flags );
 5// Result: [ '2:post:123', '2:home' ]
 6
 7// Prefix for specific site
 8$prefixed = millicache_prefix_flags( $flags, 3 );
 9// Result: [ '3:post:123', '3:home' ]

Statistics#Copied!

Per-Site Stats#Copied!

 1# Stats for specific site
 2wp millicache stats --url=site1.example.com
 3
 4# Filter by site flag prefix
 5wp millicache stats --flag="2:*"

Network Stats#Copied!

From network admin context:

 1wp millicache stats

Subdirectory vs. Subdomain#Copied!

MilliCache works with both multisite configurations:

Subdomain Multisite#Copied!

site1.example.com → Cache key includes full domain
site2.example.com → Separate cache namespace

Subdirectory Multisite#Copied!

example.com/site1/ → Cache key includes path
example.com/site2/ → Separate cache namespace

No special configuration required — MilliCache automatically handles both.

Domain Mapping#Copied!

If using domain mapping (third-party domains pointing to subsites):

  1. Each mapped domain gets its own cache entries
  2. Flags are still prefixed by site ID, not domain
  3. Clearing by site ID clears all entries for that site
 1// Clear site 3, regardless of which domains point to it
 2millicache_clear_cache_by_site_ids( [ 3 ] );

Best Practices#Copied!

1. Use Network-Wide Constants#Copied!

Keep storage configuration consistent:

 1// wp-config.php
 2define( 'MC_STORAGE_HOST', 'redis.internal' );
 3define( 'MC_STORAGE_PREFIX', 'mll_prod_' );

2. Monitor Per-Site Usage#Copied!

Check which sites consume the most cache:

 1# Stats filtered by site prefix
 2for i in 1 2 3 4 5; do
 3  echo "Site $i:"
 4  wp millicache stats --flag="$i:*" --format=json
 5done

Troubleshooting#Copied!

Cache Isn’t Isolated#Copied!

If sites seem to share cache:

  1. Verify network activation (not per-site)
  2. Check flag prefixes: wp millicache stats --flag="*" --format=json
  3. Verify MC_STORAGE_PREFIX is consistent across all sites

Network Clear Not Working#Copied!

  1. Verify you're running from network admin context
  2. Check user has manage_network capability
  3. Use explicit network ID: wp millicache clear --network=1

Inconsistent Settings#Copied!

  1. Check setting sources: wp millicache config get --show-source
  2. Verify config file naming matches domain exactly
  3. Constants override all other sources

Next Steps#Copied!