Multisite
MilliCache fully supports WordPress Multisite with per-site cache isolation, network-wide management, and multi-network compatibility.
Installation#Copied!
Network Activation#Copied!
- Install MilliCache as a regular plugin
- Network-activate from Network Admin → Plugins
- Add
WP_CACHEtowp-config.php:
1define( 'WP_CACHE', true );
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):
- Each mapped domain gets its own cache entries
- Flags are still prefixed by site ID, not domain
- 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:
- Verify network activation (not per-site)
- Check flag prefixes:
wp millicache stats --flag="*" --format=json - Verify
MC_STORAGE_PREFIXis consistent across all sites
Network Clear Not Working#Copied!
- Verify you're running from network admin context
- Check user has
manage_networkcapability - Use explicit network ID:
wp millicache clear --network=1
Inconsistent Settings#Copied!
- Check setting sources:
wp millicache config get --show-source - Verify config file naming matches domain exactly
- Constants override all other sources
Next Steps#Copied!
- WP-CLI Commands - Command line management
- Hooks & Filters - Multisite-specific hooks
- Configuration - Settings overview