### GitHub Actions CI Setup Source: https://github.com/millipress/millicache/blob/main/tests/README.md Configure GitHub Actions for continuous integration, including PHP setup, dependency installation, and test execution with coverage. ```yaml name: Tests on: [push, pull_request] jobs: test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Setup PHP uses: shivammathur/setup-php@v2 with: php-version: '8.1' coverage: xdebug - name: Install dependencies run: composer install - name: Run tests run: composer test:unit - name: Coverage run: composer test:coverage ``` -------------------------------- ### Start Test Environment with Docker and Node.js Source: https://github.com/millipress/millicache/blob/main/README.md Set up the local testing environment using npm commands. This requires Docker and Node.js to be installed. ```bash # Start test environment (requires Docker + Node.js) npm install npm run env:start ``` -------------------------------- ### Install Dependencies and Check PHP Version Source: https://github.com/millipress/millicache/blob/main/tests/README.md Install project dependencies, including the Pest testing framework. Verify that PHP version 7.4 or higher is installed. ```bash composer install php --version ``` -------------------------------- ### Install Pest PHP Source: https://github.com/millipress/millicache/blob/main/tests/README.md Install Pest as a development dependency using Composer and initialize it for your project. ```bash # Ensure Pest is installed composer require --dev pestphp/pest # Initialize Pest vendor/bin/pest --init ``` -------------------------------- ### Complete MilliCache Configuration Example Source: https://github.com/millipress/millicache/blob/main/docs/02-configuration/02-reference.md A comprehensive example of wp-config.php settings for MilliCache, including storage, cache behavior, and exclusion rules. ```php original_server = $_SERVER; }); afterEach(function () { // Restore original state $_SERVER = $this->original_server; }); it('returns server variable value', function () { $_SERVER['REQUEST_URI'] = '/test/path'; expect(ServerVars::get('REQUEST_URI'))->toBe('/test/path'); }); }); ``` -------------------------------- ### Wildcard Cache Clearing Example Source: https://github.com/millipress/millicache/blob/main/docs/03-cache-flags/03-custom-flags.md Shows how to use wildcards for efficient cache clearing. This is preferred over listing individual flags when a pattern can be used. ```php // Good: Use wildcard millicache_clear_cache_by_flags( 'product:*' ); // Avoid: Listing every flag millicache_clear_cache_by_flags( ['product:1', 'product:2', 'product:3', ...] ); ``` -------------------------------- ### Lazy Loading Example Source: https://github.com/millipress/millicache/blob/main/docs/07-developers/01-architecture.md Demonstrates lazy loading where subsystems, like storage, are only initialized upon their first use. This improves performance by deferring initialization until necessary. ```php // Storage isn't connected until the first cache operation $engine->storage()->get_cache( $key ); ``` -------------------------------- ### Install or Repair advanced-cache.php Source: https://github.com/millipress/millicache/blob/main/docs/06-wp-cli/01-commands.md Use this command to install or repair the advanced-cache.php drop-in file. The `--force` option can be used to reinstall even if the current file is up-to-date. ```bash wp millicache drop ``` ```bash wp millicache drop --force ``` -------------------------------- ### Initialize Request Processor Source: https://github.com/millipress/millicache/blob/main/docs/07-developers/01-architecture.md Instantiate the request processor with configuration to begin request handling. Use this to get the cache key and check cacheability. ```php $request = new \MilliCache\Engine\Request\Processor( $config ); // Get cache key $hash = $request->get_hash(); // Check if cacheable $cacheable = $request->is_cacheable(); ``` -------------------------------- ### Get Configuration Setting as JSON Source: https://github.com/millipress/millicache/blob/main/docs/06-wp-cli/01-commands.md Retrieve a specific configuration setting formatted as JSON. This is useful for machine-readable output. ```bash wp millicache config get cache.ttl --format=json ``` -------------------------------- ### Redis Cache Clearing Example Source: https://github.com/millipress/millicache/blob/main/docs/07-developers/01-architecture.md Illustrates efficient cache invalidation using Redis patterns. This example shows how to find keys matching a pattern and then delete them with a single command. ```redis KEYS mll:flags:post:123:* DEL [matching keys] ``` -------------------------------- ### Define No-Cache Paths (Example) Source: https://github.com/millipress/millicache/blob/main/docs/02-configuration/02-reference.md Excludes specific URL paths like '/my-account/*', '/checkout/*', and '/cart/*' from caching. Wildcards are supported. ```php define( 'MC_CACHE_NOCACHE_PATHS', [ '/my-account/*', '/checkout/*', '/cart/*', ] ); ``` -------------------------------- ### Open Interactive Redis CLI Source: https://github.com/millipress/millicache/blob/main/docs/06-wp-cli/01-commands.md Launches an interactive Redis CLI session using the configured connection settings. Requires `redis-cli` to be installed on the system. ```bash wp millicache cli ``` -------------------------------- ### Set Short TTL for News, Long TTL for Docs (PHP) Source: https://context7.com/millipress/millicache/llms.txt Configure different Time-To-Live (TTL) values for specific URL patterns. News sections get a 15-minute TTL, while documentation sections get a 1-week TTL. These rules run in the 'php' phase. ```php // 2. Short TTL for news section, long TTL for docs Rules::create( 'mysite:news-ttl', 'php' ) ->order( 10 ) ->when()->request_url( '/news/*' ) ->then()->set_ttl( 900 ) // 15 minutes ->register(); Rules::create( 'mysite:docs-ttl', 'php' ) ->order( 10 ) ->when()->request_url( '/docs/*' ) ->then()->set_ttl( 604800 ) // 1 week ->register(); ``` -------------------------------- ### Install Acorn MilliCache Package Source: https://github.com/millipress/millicache/blob/main/docs/01-getting-started/10-introduction.md Use this Composer command to install the companion package for Acorn/Roots integration. This package adds a Laravel middleware for automatic route response caching. ```bash composer require millipress/acorn-millicache ``` -------------------------------- ### Descriptive Flag Naming Examples Source: https://github.com/millipress/millicache/blob/main/docs/03-cache-flags/03-custom-flags.md Illustrates the use of descriptive flag names for better cache management. Avoid ambiguous or numeric-only flags. ```php // Good $flags[] = 'product:featured'; $flags[] = 'archive:sale'; // Avoid $flags[] = 'x'; $flags[] = '123'; ``` -------------------------------- ### Install MilliCache with Composer Source: https://github.com/millipress/millicache/blob/main/README.md Use Composer to add MilliCache to your WordPress project. This is the recommended installation method. ```bash composer require millipress/millicache ``` -------------------------------- ### Wildcard `*` Pattern Examples Source: https://github.com/millipress/millicache/blob/main/docs/03-cache-flags/03-custom-flags.md Illustrates the usage of the `*` wildcard, which matches any number of characters, for flexible cache clearing patterns. ```plaintext | Pattern | Matches | |-------------|--------------------------------------| | `post:*` | `post:1`, `post:123`, `post:999` | | `archive:*` | `archive:post`, `archive:category:5` | | `*:home` | `1:home`, `2:home` (multisite) | | `feature:*` | All feature flags | ``` -------------------------------- ### Wildcard `?` Pattern Examples Source: https://github.com/millipress/millicache/blob/main/docs/03-cache-flags/03-custom-flags.md Demonstrates the `?` wildcard, which matches exactly one character, for more precise cache clearing patterns. ```plaintext | Pattern | Matches | |----------|--------------------------------| | `post:?` | `post:1` through `post:9` only | | `?:home` | Sites with single-digit IDs | ``` -------------------------------- ### Complete Cache Integration Example Source: https://github.com/millipress/millicache/blob/main/docs/07-developers/03-api-reference.md Demonstrates a comprehensive integration of Millicache for a membership site, including custom flag handling, cache clearing on user action, TTL adjustments, and a custom REST API endpoint. ```php 'POST', 'callback' => function() { millicache_clear_cache_by_flags( [ 'membership:*' ] ); return [ 'success' => true ]; }, 'permission_callback' => function() { return current_user_can( 'manage_options' ); }, ] ); } ); ``` -------------------------------- ### Check Plugin and Redis Status (WP-CLI) Source: https://context7.com/millipress/millicache/llms.txt Get an overview of the MilliCache plugin's status and its connection to the Redis server. ```bash # ── Diagnostics ───────────────────────────────────────────────────────────── wp millicache status # overall plugin + Redis status ``` -------------------------------- ### Verify MilliCache Installation with WP-CLI Source: https://context7.com/millipress/millicache/llms.txt Use WP-CLI commands to check the status and test the connection of your MilliCache installation. This helps confirm that the plugin is active and communicating correctly with the storage backend. ```bash # Verify installation with WP-CLI wp millicache status # Expected output: # +-------------------+------------------+ # | property | status | # +-------------------+------------------+ # | plugin_version | 1.6.0 | # | wp_cache | enabled | # | advanced_cache | symlink | # | storage_connected | yes | # | storage_version | 7.2.4 | # | cache_entries | 0 | # | cache_size | 0 B | # +-------------------+------------------+ # Run full connection diagnostics wp millicache test # +-------------+--------+------------------+ # | test | status | info | # +-------------+--------+------------------+ # | Connection | PASS | Connected | # | Ping | PASS | 0.23ms | # | Write | PASS | Stored test data | # | Read | PASS | Data verified | # | Delete | PASS | Cleaned up | # +-------------+--------+------------------+ ``` -------------------------------- ### wp millicache config get Source: https://github.com/millipress/millicache/blob/main/docs/06-wp-cli/01-commands.md Displays current configuration values, with options to specify a key, show the source of values, and format the output. ```APIDOC ## wp millicache config get ### Description Display current configuration values. ### Method `wp millicache config get` ### Parameters #### Arguments - **** (string) - Module or setting key (e.g., `cache` or `cache.ttl`) #### Options - **--show-source** (boolean) - Show where each value comes from - **--format=** (string) - Output: `table`, `json`, `yaml`, `csv` (default: `table`) ### Examples ```bash # View all settings wp millicache config get # View specific module wp millicache config get cache # View specific setting wp millicache config get cache.ttl # View setting as JSON wp millicache config get cache.ttl --format=json # Show setting sources wp millicache config get --show-source ``` ### Source values - `constant` — Defined in wp-config.php - `file` — Set in config file - `database` — Saved via admin or CLI - `default` — Built-in default value ``` -------------------------------- ### General and Command-Specific Help Source: https://github.com/millipress/millicache/blob/main/docs/06-wp-cli/01-commands.md Commands to access help documentation for the MilliCache WP-CLI integration. You can get general help for the `millicache` command or specific help for subcommands like `clear` or `config`. ```bash # General help wp help millicache ``` ```bash # Command-specific help wp help millicache clear wp help millicache config ``` -------------------------------- ### Limiting Flag Count Example Source: https://github.com/millipress/millicache/blob/main/docs/03-cache-flags/03-custom-flags.md Demonstrates how to limit the number of flags to reduce storage overhead. Avoid generating excessive flags, especially from dynamic meta data. ```php // Good: Few targeted flags $flags[] = 'post:' . $post->ID; $flags[] = 'archive:' . $post->post_type; // Avoid: Excessive flags foreach ( get_all_meta( $post->ID ) as $key => $value ) { $flags[] = "meta:{$key}:{$value}"; // Could be hundreds! } ``` -------------------------------- ### Get Millicache Configuration Settings Source: https://context7.com/millipress/millicache/llms.txt Retrieve all settings, a specific module's settings, or a single key's value. Use --show-source to see where the setting is defined (constant, file, database, or default). ```bash wp millicache config get # all settings ``` ```bash wp millicache config get cache # one module ``` ```bash wp millicache config get cache.ttl # one key ``` ```bash wp millicache config get --show-source # show constant / file / database / default source ``` -------------------------------- ### Setup MilliCache Rules Source: https://github.com/millipress/millicache/blob/main/docs/04-rules/03-examples.md Add rules early in your plugin or theme. Rules register themselves, but you can use ->on() to hook into WordPress actions if needed. ```php use MilliCache\Deps\MilliRules\Rules; // You do not need to wrap them into an add_action() call - rules register themselves // Instead use ->on() to hook into WordPress actions if needed ``` -------------------------------- ### Run End-to-End Tests Source: https://github.com/millipress/millicache/blob/main/README.md Execute the end-to-end tests for MilliCache within the started test environment. ```bash # Run e2e tests npm run env:e2e ``` -------------------------------- ### Targeted Cache Clearing Example Source: https://github.com/millipress/millicache/blob/main/docs/05-usage/20-cache-clearing.md Prefer clearing specific content using `millicache_clear_cache_by_post_ids()` over clearing the entire cache with `millicache_reset_cache()` for better performance. ```php // Good: Clear specific content millicache_clear_cache_by_post_ids( [ $post_id ] ); // Avoid: Clear everything millicache_reset_cache(); ``` -------------------------------- ### Per-Site Cache Configuration File Source: https://github.com/millipress/millicache/blob/main/docs/05-usage/30-multisite.md Example of a per-site configuration file that overrides network settings. This file allows for specific cache TTL settings for individual sites. ```php [ // ... 'ttl' => 3600, // 1 hour for this site ], ]; ``` -------------------------------- ### Get Specific Configuration Module Source: https://github.com/millipress/millicache/blob/main/docs/06-wp-cli/01-commands.md Retrieve configuration values for a specific module, such as 'cache'. This helps in inspecting settings for a particular feature. ```bash wp millicache config get cache ``` -------------------------------- ### Define Ignore Cookies (Example) Source: https://github.com/millipress/millicache/blob/main/docs/02-configuration/02-reference.md Specifies cookies like '_*' for analytics and '__utm*' for UTM tracking to be ignored in cache key calculation. Wildcards are supported. ```php define( 'MC_CACHE_IGNORE_COOKIES', [ '_*', // Analytics '__utm*', // UTM tracking ] ); ``` -------------------------------- ### Get Specific Configuration Setting Source: https://github.com/millipress/millicache/blob/main/docs/06-wp-cli/01-commands.md View the value of a particular configuration setting, like 'cache.ttl'. This allows for precise inspection of individual settings. ```bash wp millicache config get cache.ttl ``` -------------------------------- ### Define Ignore Request Keys (Example) Source: https://github.com/millipress/millicache/blob/main/docs/02-configuration/02-reference.md Excludes query parameters like '_*', 'utm_*', 'fbclid', and 'gclid' from cache key calculations. Wildcards are supported. ```php define( 'MC_CACHE_IGNORE_REQUEST_KEYS', [ '_*', 'utm_*', 'fbclid', 'gclid', ] ); ``` -------------------------------- ### Run Millicache Redis Tests Source: https://github.com/millipress/millicache/blob/main/docs/06-wp-cli/01-commands.md Executes a series of tests to verify the Redis connection and functionality. This command helps diagnose potential issues with the Redis setup. ```bash wp millicache test ``` ```text +-------------+--------+------------------+ | test | status | info | +-------------+--------+------------------+ | Connection | PASS | Connected | | Ping | PASS | 0.23ms | | Write | PASS | Stored test data | | Read | PASS | Data verified | | Delete | PASS | Cleaned up | +-------------+--------+------------------+ ``` -------------------------------- ### Get Millicache Configuration Sources Source: https://github.com/millipress/millicache/blob/main/docs/05-usage/30-multisite.md To diagnose inconsistent settings, check the sources of your Millicache configuration. This command displays where each setting is defined, helping to identify overrides and potential conflicts. ```bash wp millicache config get --show-source ``` -------------------------------- ### Development Environment Configuration Source: https://github.com/millipress/millicache/blob/main/docs/02-configuration/01-overview.md Set up a development environment with a short cache TTL and enabled debug headers for easier troubleshooting. ```php define( 'MC_CACHE_TTL', 60 ); // 1 minute define( 'MC_CACHE_DEBUG', true ); // Show debug headers ``` -------------------------------- ### Accessing the MilliCache Engine Source: https://github.com/millipress/millicache/blob/main/docs/07-developers/01-architecture.md Demonstrates how to obtain an instance of the main Engine class, either via a helper function or directly. Shows how to access its core subsystems. ```php $engine = millicache(); // Or access Engine directly $engine = \MilliCache\Engine::instance(); // Access subsystems $engine->storage(); // Redis connection $engine->flags(); // Flag manager $engine->config(); // Configuration $engine->options(); // Runtime overrides $engine->cache(); // Cache manager $engine->clear(); // Invalidation manager $engine->rules(); // Rules manager ``` -------------------------------- ### Run Connection and Performance Tests (WP-CLI) Source: https://context7.com/millipress/millicache/llms.txt Execute a series of tests to verify the connection to Redis, including ping, write, read, and delete operations. ```bash wp millicache test # connection + ping + write + read + delete ``` -------------------------------- ### wp millicache drop Source: https://github.com/millipress/millicache/blob/main/docs/06-wp-cli/01-commands.md Installs or repairs the advanced-cache.php file. ```APIDOC ## wp millicache drop ### Description Install/repair advanced-cache.php. ### Method `wp millicache drop` ``` -------------------------------- ### GET /wp-json/millicache/v1/status Source: https://github.com/millipress/millicache/blob/main/docs/07-developers/03-api-reference.md Retrieves the current status of the MilliCache plugin and its cache. ```APIDOC ## GET /wp-json/millicache/v1/status ### Description Get plugin and cache status. ### Method GET ### Endpoint /wp-json/millicache/v1/status ### Query Parameters - `network` (string) - Optional - Set to "true" for network stats in multisite. ### Response #### Success Response (200) - `plugin_name` (string) - The name of the plugin. - `version` (string) - The current version of the plugin. - `cache` (object) - Cache statistics. - `entries` (integer) - Number of cache entries. - `size` (integer) - Total size of the cache in bytes. - `size_h` (string) - Human-readable cache size. - `storage` (object) - Storage details. - `connected` (boolean) - Whether storage is connected. - `version` (string) - Version of the storage system. - `memory` (object) - Memory usage details. - `used` (integer) - Memory used in bytes. - `max` (integer) - Maximum memory available in bytes. - `dropin` (object) - Drop-in configuration status. - `status` (string) - Status of the drop-in (e.g., "symlink"). - `outdated` (boolean) - Whether the drop-in is outdated. - `settings` (object) - Plugin settings status. - `has_defaults` (boolean) - Whether settings are using defaults. - `has_backup` (boolean) - Whether a settings backup exists. ### Response Example ```json { "plugin_name": "millicache", "version": "1.0.0", "cache": { "entries": 142, "size": 2856432, "size_h": "2.7 MB" }, "storage": { "connected": true, "version": "7.2.4", "memory": { "used": 12500000, "max": 268435456 } }, "dropin": { "status": "symlink", "outdated": false }, "settings": { "has_defaults": false, "has_backup": true } } ``` ``` -------------------------------- ### Define Cache Connection with Authentication Source: https://github.com/millipress/millicache/blob/main/docs/08-storage-backends/01-overview.md Configure host, port, username, and password for authenticated access to your storage backend. ```php define( 'MC_STORAGE_HOST', 'redis.example.com' ); define( 'MC_STORAGE_PORT', 6379 ); define( 'MC_STORAGE_USERNAME', 'your-username' ); define( 'MC_STORAGE_PASSWORD', 'your-password' ); ``` -------------------------------- ### Open Interactive Redis CLI (WP-CLI) Source: https://context7.com/millipress/millicache/llms.txt Launch an interactive Redis command-line interface pre-configured with the credentials specified in your MilliCache settings. ```bash wp millicache cli # open interactive redis-cli with configured creds ``` -------------------------------- ### View Current MilliCache Configuration and Test Connection Source: https://github.com/millipress/millicache/blob/main/docs/02-configuration/01-overview.md Use WP-CLI commands to view all settings with their sources, test the storage connection, and retrieve cache statistics. ```bash # All settings with sources wp millicache config get --show-source # Test connection wp millicache test # Cache statistics wp millicache stats ``` -------------------------------- ### Define No-Cache Cookies (Example) Source: https://github.com/millipress/millicache/blob/main/docs/02-configuration/02-reference.md Excludes cookies matching 'wp-*pass*', 'comment_author_*', and 'woocommerce_cart_hash' from cache. Wildcards are supported. ```php define( 'MC_CACHE_NOCACHE_COOKIES', [ 'wp-*pass*', 'comment_author_*', 'woocommerce_cart_hash', ] ); ``` -------------------------------- ### Get Cache Status Source: https://context7.com/millipress/millicache/llms.txt Retrieves the current status of the MilliCache, including cache statistics, storage information, and plugin details. ```APIDOC ## GET /wp-json/millicache/v1/status ### Description Retrieves the current status of the MilliCache, including cache statistics, storage information, and plugin details. ### Method GET ### Endpoint /wp-json/millicache/v1/status ### Request Example ```bash curl -s \ -H "X-WP-Nonce: $(wp eval 'echo wp_create_nonce("wp_rest");')" \ https://example.com/wp-json/millicache/v1/status | jq . ``` ### Response #### Success Response (200) - **plugin_name** (string) - The name of the plugin. - **version** (string) - The current version of the plugin. - **cache** (object) - Cache statistics. - **entries** (integer) - Number of cache entries. - **size** (integer) - Total size of the cache in bytes. - **size_h** (string) - Human-readable cache size. - **storage** (object) - Storage details. - **connected** (boolean) - Indicates if the storage is connected. - **version** (string) - Version of the storage system. - **memory** (object) - Memory usage details. - **used** (integer) - Memory used in bytes. - **max** (integer) - Maximum memory available in bytes. - **dropin** (object) - Drop-in status. - **status** (string) - Status of the drop-in (e.g., "symlink"). - **outdated** (boolean) - Indicates if the drop-in is outdated. - **settings** (object) - Settings status. - **has_defaults** (boolean) - Indicates if default settings are in use. - **has_backup** (boolean) - Indicates if a backup exists. #### Response Example ```json { "plugin_name": "millicache", "version": "1.6.0", "cache": { "entries": 142, "size": 2856432, "size_h": "2.7 MB" }, "storage": { "connected": true, "version": "7.2.4", "memory": { "used": 12500000, "max": 268435456 } }, "dropin": { "status": "symlink", "outdated": false }, "settings": { "has_defaults": false, "has_backup": true } } ``` ``` -------------------------------- ### Retrieve MilliCache Storage Configuration Source: https://github.com/millipress/millicache/blob/main/docs/09-troubleshooting/01-common-issues.md Get the current storage configuration for MilliCache, which is essential for verifying connection details and troubleshooting. ```bash wp millicache config get storage ``` -------------------------------- ### View Configuration via WP-CLI Source: https://github.com/millipress/millicache/blob/main/docs/01-getting-started/20-installation.md Retrieve the current MilliCache configuration settings using this WP-CLI command. ```bash wp millicache config get ``` -------------------------------- ### Enable Gzip Compression for Cache Source: https://github.com/millipress/millicache/blob/main/docs/02-configuration/02-reference.md Enables gzip compression for cached content. Requires the `ext-zlib` PHP extension. ```php define( 'MC_CACHE_GZIP', true ); ``` -------------------------------- ### Backup and Restore Configuration Settings Source: https://github.com/millipress/millicache/blob/main/docs/06-wp-cli/01-commands.md Commands for backing up, restoring, exporting, and importing MilliCache configuration settings. Settings can be backed up manually, restored from a backup, or exported/imported to/from a JSON file. ```bash # Create a manual backup wp millicache config backup ``` ```bash # Restore from backup wp millicache config restore ``` ```bash # Export to file for external backup wp millicache config export --file=backup.json ``` ```bash # Import from file wp millicache config import --file=backup.json ``` -------------------------------- ### Run All Tests Before Committing Source: https://github.com/millipress/millicache/blob/main/tests/README.md Execute the full test suite using `composer test` before committing code changes to ensure all tests pass and coverage is maintained. ```bash # Before committing composer test ``` -------------------------------- ### Common Workflow: After Deployment Source: https://github.com/millipress/millicache/blob/main/docs/06-wp-cli/01-commands.md A sequence of commands to run after deploying changes. This includes forcing a reinstall of advanced-cache.php, running a test, and clearing the cache. ```bash wp millicache drop --force wp millicache test wp millicache clear ``` -------------------------------- ### Get Millicache Status (REST API) Source: https://github.com/millipress/millicache/blob/main/docs/07-developers/03-api-reference.md Retrieves the current status of the Millicache plugin, including cache statistics, storage details, and configuration. ```json { "plugin_name": "millicache", "version": "1.0.0", "cache": { "entries": 142, "size": 2856432, "size_h": "2.7 MB" }, "storage": { "connected": true, "version": "7.2.4", "memory": { "used": 12500000, "max": 268435456 } }, "dropin": { "status": "symlink", "outdated": false }, "settings": { "has_defaults": false, "has_backup": true } } ``` -------------------------------- ### Run Unit Tests with Composer Source: https://github.com/millipress/millicache/blob/main/tests/README.md Execute all unit tests for the project using the predefined composer script. This command is a shortcut for running the Pest test suite. ```bash composer test:unit ``` -------------------------------- ### Define Basic Cache Connection Source: https://github.com/millipress/millicache/blob/main/docs/08-storage-backends/01-overview.md Use these constants in wp-config.php to establish a basic connection to your storage backend. ```php define( 'WP_CACHE', true ); define( 'MC_STORAGE_HOST', '127.0.0.1' ); define( 'MC_STORAGE_PORT', 6379 ); ``` -------------------------------- ### MilliCache Storage Operations Source: https://github.com/millipress/millicache/blob/main/docs/07-developers/01-architecture.md Illustrates basic low-level operations for interacting with the Redis cache storage, such as setting, getting, and deleting cache entries. ```php $storage = $engine->storage(); // Low-level operations $storage->set_cache( $key, $data, $flags ); $storage->get_cache( $key ); $storage->delete_cache( $key ); $storage->is_connected(); $storage->get_status(); ``` -------------------------------- ### Good vs. Avoid: Descriptive Rule IDs Source: https://github.com/millipress/millicache/blob/main/docs/04-rules/03-examples.md Illustrates the recommended practice of using namespaced and descriptive IDs for rules (e.g., 'mysite:woo-cart-bypass') over generic ones (e.g., 'rule1'). ```php // Good - namespace:purpose Rules::create( 'mysite:woo-cart-bypass', 'php' ) // Avoid - generic Rules::create( 'rule1', 'php' ) ``` -------------------------------- ### Remove Old Drop-in File Source: https://github.com/millipress/millicache/blob/main/docs/09-troubleshooting/01-common-issues.md Manually remove an existing `advanced-cache.php` file from another plugin before installing Millicache's drop-in. This prevents conflicts. ```bash rm wp-content/advanced-cache.php ``` -------------------------------- ### Recommended Redis Server Configuration Source: https://github.com/millipress/millicache/blob/main/docs/08-storage-backends/01-overview.md Essential Redis server settings for optimal WordPress caching performance, including memory limits, persistence, and security. ```conf # Memory allocation (adjust based on your needs) maxmemory 256mb maxmemory-policy allkeys-lru # Persistence (optional - cache can be regenerated) save "" appendonly no # Performance tcp-keepalive 300 timeout 0 # Security (if exposed to network) bind 127.0.0.1 requirepass your-strong-password ``` -------------------------------- ### Hierarchical Flag Design Pattern Source: https://github.com/millipress/millicache/blob/main/docs/03-cache-flags/03-custom-flags.md Implement a hierarchical naming structure for flags to achieve granular control over cache clearing, as shown in this e-commerce example. ```php // E-commerce example $flags[] = 'product'; // All products $flags[] = 'product:category:5'; // Products in category 5 $flags[] = 'product:5:sku:ABC123'; // Specific product variant // Clear all products millicache_clear_cache_by_flags( 'product:*' ); // Clear category only millicache_clear_cache_by_flags( 'product:category:5' ); ``` -------------------------------- ### wp millicache cli Source: https://github.com/millipress/millicache/blob/main/docs/06-wp-cli/01-commands.md Opens an interactive Redis command-line interface. ```APIDOC ## wp millicache cli ### Description Open interactive Redis CLI. ### Method `wp millicache cli` ``` -------------------------------- ### Multisite Cache Clearing and Stats Source: https://github.com/millipress/millicache/blob/main/docs/06-wp-cli/01-commands.md Commands for managing cache in multisite installations. You can clear cache for specific sites, the entire network, or retrieve statistics for a specific site. ```bash wp millicache clear --url=site1.example.com ``` ```bash wp millicache clear --site=1,2,3 ``` ```bash wp millicache clear --network=1 ``` ```bash wp millicache stats --flag="2:*" ``` -------------------------------- ### Clear Cache with Multisite Flags (WP-CLI) Source: https://github.com/millipress/millicache/blob/main/docs/03-cache-flags/03-custom-flags.md When using WP-CLI on a multisite installation, prefix flags with the site ID or use a wildcard `*` to target specific sites or all sites. ```bash # Multisite: Include site prefix wp millicache clear --flag="2:post:*" wp millicache clear --flag="*:home" ``` -------------------------------- ### Troubleshoot Cache Isolation Issues Source: https://github.com/millipress/millicache/blob/main/docs/05-usage/30-multisite.md If sites appear to share cache, verify network activation and check flag prefixes. Ensure MC_STORAGE_PREFIX is consistent across all sites. ```bash wp millicache stats --flag="*" --format=json ``` -------------------------------- ### MilliCache Cache Manager Operations Source: https://github.com/millipress/millicache/blob/main/docs/07-developers/01-architecture.md Provides examples of using the Cache Manager to check for existing cached content and to store new content with associated headers and flags. ```php $cache = $engine->cache(); // Check for cached content $result = $cache->get( $request_hash ); // Store content $cache->set( $request_hash, $content, $headers, $flags ); ``` -------------------------------- ### Create and Register a Rule Source: https://github.com/millipress/millicache/blob/main/docs/04-rules/01-introduction.md Use the fluent API to create a rule with a unique ID and specify its execution phase. Set the rule's priority using 'order' and define conditions with 'when' and actions with 'then'. ```php use MilliCache\Deps\MilliRules\Rules; Rules::create( 'mysite:example-rule', 'php' ) // Create rule with ID and phase ->order( 10 ) // Set priority ->when() // Start conditions ->request_url( '/news/*' ) // Match URL pattern ->then() // Start actions ->set_ttl( 1800 ) // Set 30-minute TTL ->register(); // Register the rule ``` -------------------------------- ### Check MilliCache Status and Configuration Source: https://github.com/millipress/millicache/blob/main/docs/09-troubleshooting/01-common-issues.md Use these WP-CLI commands to check the overall status, test Redis connections, view cache statistics, and inspect configuration sources. ```bash wp millicache status ``` ```bash wp millicache test ``` ```bash wp millicache stats ``` ```bash wp millicache config get --show-source ``` -------------------------------- ### Cache Flags for Invalidation Source: https://github.com/millipress/millicache/blob/main/docs/05-usage/10-how-caching-works.md Provides examples of flags used to tag cached pages, enabling targeted invalidation when specific content, like a post or archive, is updated. ```text Homepage: [home, archive:post] Single post: [post:123] Archives: [archive:category:5, archive:post] Author: [archive:author:1] ``` -------------------------------- ### Configure Multiple Sites with Different Prefixes/Databases Source: https://github.com/millipress/millicache/blob/main/docs/08-storage-backends/01-overview.md Isolate multiple WordPress sites on the same storage server by defining unique database numbers and key prefixes for each site. ```php // Site A define( 'MC_STORAGE_DB', 0 ); define( 'MC_STORAGE_PREFIX', 'sitea' ); // Site B define( 'MC_STORAGE_DB', 1 ); define( 'MC_STORAGE_PREFIX', 'siteb' ); ``` -------------------------------- ### wp millicache config import Source: https://github.com/millipress/millicache/blob/main/docs/06-wp-cli/01-commands.md Imports settings from a JSON file. ```APIDOC ## wp millicache config import ### Description Import settings from JSON. ### Method `wp millicache config import` ``` -------------------------------- ### Get Per-Site Cache Statistics via WP-CLI Source: https://github.com/millipress/millicache/blob/main/docs/05-usage/30-multisite.md Retrieve cache statistics for a specific site using its URL, or filter statistics network-wide using flag prefixes. ```bash # Stats for specific site wp millicache stats --url=site1.example.com # Filter by site flag prefix wp millicache stats --flag="2:*" ``` -------------------------------- ### Run All Tests with Verbose Output Source: https://github.com/millipress/millicache/blob/main/tests/README.md Execute all tests in the project, including linting and static analysis, with verbose output enabled. This provides detailed information about the test execution. ```bash composer test vendor/bin/pest -v ``` -------------------------------- ### Prefix Flags for a Specific Site Source: https://github.com/millipress/millicache/blob/main/docs/03-cache-flags/02-built-in-flags.md Manually prefix a list of flags with a specified site ID. This is useful for targeting cache operations on a particular site within a multisite installation. ```php // Prefix flags for a specific site $flags = millicache_prefix_flags( ['home', 'post:123'], $site_id = 2 ); // Returns: ['2:home', '2:post:123'] in multisite ``` -------------------------------- ### Feature Flag Design Pattern Source: https://github.com/millipress/millicache/blob/main/docs/03-cache-flags/03-custom-flags.md Tag pages with feature flags to manage cache clearing for cross-cutting concerns. This example tags pages with dynamic pricing or real-time inventory. ```php add_filter( 'millicache_flags_for_request', function( $flags ) { // Tag pages showing dynamic pricing if ( has_dynamic_pricing() ) { $flags[] = 'feature:dynamic-pricing'; } // Tag pages with real-time inventory if ( shows_inventory() ) { $flags[] = 'feature:inventory'; } return $flags; } ); // When pricing engine updates, clear all affected pages millicache_clear_cache_by_flags( 'feature:dynamic-pricing' ); ``` -------------------------------- ### Manage Settings Source: https://context7.com/millipress/millicache/llms.txt Resets plugin settings to their defaults or restores settings from the latest backup. ```APIDOC ## POST /wp-json/millicache/v1/settings ### Description Resets plugin settings to their defaults or restores settings from the latest backup. ### Method POST ### Endpoint /wp-json/millicache/v1/settings ### Parameters #### Request Body - **action** (string) - Required - The action to perform. Can be "reset" or "restore". ### Request Example (Reset Settings) ```bash curl -s -X POST \ -H "X-WP-Nonce: $NONCE" \ -H "Content-Type: application/json" \ -d '{"action":"reset"}' \ https://example.com/wp-json/millicache/v1/settings ``` ### Request Example (Restore from Backup) ```bash curl -s -X POST \ -H "X-WP-Nonce: $NONCE" \ -H "Content-Type: application/json" \ -d '{"action":"restore"}' \ https://example.com/wp-json/millicache/v1/settings ``` ### Response #### Success Response (200) - **success** (boolean) - Indicates if the operation was successful. - **message** (string) - A message describing the result of the operation. - **action** (string) - The action that was performed. #### Response Example ```json { "success": true, "message": "Settings have been reset.", "action": "reset" } ``` ``` -------------------------------- ### Remove Built-in Flag via Rule Source: https://github.com/millipress/millicache/blob/main/docs/03-cache-flags/03-custom-flags.md Use MilliRules to remove a default flag based on specific conditions. This example prevents the 'archive:post' flag from being applied to product archives. ```php Rules::create( 'mysite:no-archive-flag' ) ->on( 'template_redirect', 30 ) ->when() ->is_post_type_archive( 'product' ) ->then() ->remove_flag( 'archive:post' ) ->register(); ``` -------------------------------- ### Run Tests with Coverage Report Source: https://github.com/millipress/millicache/blob/main/tests/README.md Execute all tests and generate a code coverage report. This helps in understanding which parts of the code are covered by tests. ```bash composer test:coverage ``` -------------------------------- ### Add Custom Flags via Rule Action Source: https://github.com/millipress/millicache/blob/main/docs/03-cache-flags/03-custom-flags.md Utilize the MilliRules system to define condition-based custom flags. This example adds a 'promo:seasonal' flag when a product has the 'seasonal' term. ```php use MilliCache\Deps\MilliRules\Rules; Rules::create( 'mysite:seasonal-flag' ) ->on( 'template_redirect', 25 ) ->when() ->has_term( 'seasonal', 'product_cat' ) ->then() ->add_flag( 'promo:seasonal' ) ->register(); ``` -------------------------------- ### wp millicache config backup Source: https://github.com/millipress/millicache/blob/main/docs/06-wp-cli/01-commands.md Creates a backup of the current settings. ```APIDOC ## wp millicache config backup ### Description Create settings backup. ### Method `wp millicache config backup` ``` -------------------------------- ### Clear Cache for Multisite Networks or Specific Sites (WP-CLI) Source: https://context7.com/millipress/millicache/llms.txt Manage cache across a multisite installation by clearing cache for specific sites using their IDs or for an entire network using its ID. ```bash # Multisite wp millicache clear --site=2,3 wp millicache clear --network=1 ``` -------------------------------- ### Bootstrap Rule: Avoid Complex Logic Source: https://github.com/millipress/millicache/blob/main/docs/04-rules/03-examples.md Example of complex logic to avoid in Bootstrap rules. Loading files, database queries, or other heavy operations can significantly slow down the initial request processing. ```php // Avoid in bootstrap - complex logic ->when()->custom( 'complex', function() { // Loading files, database, etc. defeats the purpose } ) ``` -------------------------------- ### Millicache Deployment Workflow Source: https://context7.com/millipress/millicache/llms.txt A common deployment sequence involving dropping the cache, testing the connection, and clearing the cache. ```bash wp millicache drop --force && wp millicache test && wp millicache clear ``` -------------------------------- ### Recommended Redis Configuration Source: https://context7.com/millipress/millicache/llms.txt Essential `redis.conf` settings for optimal WordPress caching performance and reliability. Includes memory management, persistence, and network settings. ```conf maxmemory 256mb maxmemory-policy allkeys-lru # evict least-recently-used entries automatically save "" # disable persistence (cache is regeneratable) appendonly no tcp-keepalive 300 bind 127.0.0.1 # restrict to localhost unless multi-server requirepass your-strong-password ``` -------------------------------- ### Check Specific Site Cache Flags Source: https://github.com/millipress/millicache/blob/main/docs/09-troubleshooting/01-common-issues.md Inspect cache flags for individual sites in a multisite setup using WP-CLI. This is crucial for verifying cache isolation and troubleshooting cross-site content issues. ```bash wp millicache stats --flag="1:*" # Site 1 wp millicache stats --flag="2:*" # Site 2 ``` -------------------------------- ### Get Stats for Specific Site Prefixes Source: https://github.com/millipress/millicache/blob/main/docs/05-usage/30-multisite.md Use this command to retrieve Millicache statistics for sites matching a specific flag prefix. This is useful for isolating and checking cache status on a per-site basis. ```bash for i in 1 2 3 4 5; do echo "Site $i:" wp millicache stats --flag="$i:*" --format=json done ``` -------------------------------- ### Import Millicache Configuration Source: https://github.com/millipress/millicache/blob/main/docs/06-wp-cli/01-commands.md Imports Millicache settings from a JSON file. By default, settings are merged with existing ones, but you can choose to replace all settings. A backup is automatically created before importing. ```bash wp millicache config import --file= [--merge] [--no-merge] [--yes] ``` ```bash # Import from file (merges by default) wp millicache config import --file=settings.json ``` ```bash # Replace all settings wp millicache config import --file=settings.json --no-merge ``` ```bash # Skip confirmation wp millicache config import --file=settings.json --yes ``` -------------------------------- ### Compound Conditions: NOT Source: https://github.com/millipress/millicache/blob/main/docs/04-rules/03-examples.md Utilizes `when_none()` to create a 'NOT' condition, ensuring the rule applies only when none of the specified request methods (GET or HEAD) are used. This is useful for targeting non-standard HTTP methods. ```php // NOT - none of the conditions should match Rules::create( 'mysite:none-match', 'php' ) ->when_none() ->request_method( 'GET' ) ->request_method( 'HEAD' ) ->then() // Runs if NEITHER GET nor HEAD ->do_cache( false, 'Non-cacheable method' ) ->register(); ``` -------------------------------- ### Bootstrap Rule: Simple String Match Source: https://github.com/millipress/millicache/blob/main/docs/04-rules/03-examples.md Example of a simple and fast condition suitable for Bootstrap rules, which run early in the request lifecycle. Avoid complex logic or external dependencies in Bootstrap rules. ```php // Good - simple string match ->when()->request_url( '/api/*' ) ``` -------------------------------- ### Best Practices for Cache Clearing Source: https://github.com/millipress/millicache/blob/main/docs/05-usage/20-cache-clearing.md Recommendations for efficient and effective cache clearing strategies, emphasizing targeted clearing and preferring expiration over deletion. ```APIDOC ## Best Practices ### 1. Use Targeted Clearing Clear only what's necessary: ```php // Good: Clear specific content millicache_clear_cache_by_post_ids( [ $post_id ] ); // Avoid: Clear everything millicache_reset_cache(); ``` ### 2. Prefer Expire Over Delete For non-critical updates, expire instead of delete: ```php millicache_clear_cache_by_post_ids( [ $post_id ], true ); // expire = true ``` ### 3. Batch Related Clears Clear related items together: ```php // Clear post and its relationships $flags = [ "post:{$post_id}", 'home', 'archive:post', ]; millicache_clear_cache_by_flags( $flags ); ``` ### 4. Use Custom Flags for Cross-Cutting Concerns Add flags for content that should clear together: ```php // Tag all pages showing a promotion add_filter( 'millicache_flags_for_request', function( $flags ) { if ( is_promotion_active() ) { $flags[] = 'promo:summer-sale'; } return $flags; } ); // Clear all promotion pages when the sale ends millicache_clear_cache_by_flags( [ 'promo:summer-sale' ] ); ``` ``` -------------------------------- ### Create Millicache Configuration Backup Source: https://github.com/millipress/millicache/blob/main/docs/06-wp-cli/01-commands.md Manually creates a backup of the current Millicache settings. These backups expire after 12 hours and are also automatically generated before reset and import operations. ```bash wp millicache config backup ``` -------------------------------- ### Prefix Flags with Current Site's Prefix Source: https://github.com/millipress/millicache/blob/main/docs/03-cache-flags/02-built-in-flags.md Use this helper function to automatically prefix flags with the current site's ID in multisite or multi-network setups. It returns the flags as they would be stored. ```php // Prefix flags with the current site's prefix $prefix = millicache_get_flag_prefix( ['home', 'post:123'] ); // Returns: ['home', 'post:123'] (single site), ['2:home', '2:post:123'] (multisite), or ['1:2:home', '1:2:post:123'] (multi-network) ```