=== QuantumCache ===
Contributors: adelong01
Donate link: https://paypal.me/quantumcache
Tags: caching, performance, redis, database, multisite
Requires at least: 6.0
Tested up to: 6.9
Requires PHP: 8.0
Stable tag: 0.1.6
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Speeds up WordPress by caching database queries and fragments for anonymous visitors using Redis or MySQL, without storing cache data in wp_options.

== Description ==

QuantumCache speeds up WordPress by caching database query results (not full pages). It integrates with WordPress query execution to cache post ID lists and content fragments that WordPress uses to build pages, reducing database load while preserving correct invalidation.

It is *not* an output buffer or page cache, and it does not replace existing page caching solutions.


### Features
* Caches the results of the main front-end `WP_Query` for anonymous requests.
* Tag-based invalidation: purge by post ID, post type, or taxonomy.
* Fragment caching for `the_content` (classic) and core blocks such as `core/post-content`, `core/latest-posts`, `core/archives`, and `core/navigation`.
* Multiple storage modes:
  * Auto – use Redis if available, otherwise fall back to MySQL.
  * Redis – fastest mode; uses the PHP Redis extension.
  * MySQL – portable fallback using compact tables (`qc_entries`, `qc_tagmap`).
* Compatible with the Redis Object Cache drop-in.
* Avoids wp_options and postmeta storage – all cache data is stored in Redis or
  QuantumCache-owned database tables.
* Multisite-aware: per-site prefixes and per-site tables.

### Performance summary
In benchmarks on a plugin-heavy WordPress site (WooCommerce + Yoast SEO), 
QuantumCache reduced per-request database queries by ~99% on cached pages 
and achieved cache hit rates exceeding 97% with Redis.

Under production-like load with a networked database, Redis mode delivered 
13–18% lower TTFB at both median and 95th percentile versus uncached 
baseline. MySQL fallback mode delivered 4–8% improvement under the same 
conditions.

Actual results depend on theme, plugins, database topology, and traffic 
patterns.

### Debug headers (optional)
Enable *Settings → QuantumCache → Send X-QC debug headers* to view cache status in HTTP responses:
* `X-QC-Main: HIT | MISS | STORE`
* `X-QC-Store: AUTO | redis | mysql`
* `X-QC-Hydrated:` number of posts loaded from cache

Append `?qc_nocache=1` to any URL to bypass caching for that request.

Debug headers are sent only when explicitly enabled in settings and contain no
personal or user-specific data.

== Installation ==

1. Upload the `quantumcache` folder to `/wp-content/plugins/` and activate it.
2. (Optional) You may install the Redis Object Cache plugin for additional Redis features. QuantumCache works independently.
3. Go to *Settings → QuantumCache*:
   * Choose a store mode: Auto, Redis, or MySQL.
   * Configure Redis host/port if not already set by constants.
   * Optionally enable debug headers.
4. Load a public page twice. On the second load, the response should include `X-QC-Main: HIT`.

== Frequently Asked Questions ==

= Does it cache logged-in users? =
No. QuantumCache focuses on anonymous (front-end) traffic to ensure safe invalidation. Logged-in caching is not included.

= Do I need Redis? =
Redis is recommended for best performance, but not required. QuantumCache automatically falls back to its internal MySQL store.

= Does it cache admin pages, feeds, or searches? =
No. Those are intentionally excluded.

= Is it Multisite-compatible? =
Yes. Each site uses its own prefix and tables. Purge actions apply per site.

= How do I purge the cache? =
From *Settings → QuantumCache*:
* Purge Everything – clears all QuantumCache entries for this site.
* Purge by Tag – e.g. `post:123` or `taxonomy:category`.
* Purge by URL – resolves to post/taxonomy tags automatically.

= Which fragments are cached? =
* Classic themes – `the_content` on singulars.
* Block themes – `core/post-content` and common navigation/listing blocks.

= Does it cache dynamic content or nonces? =
No. Fragments containing nonces, tokens, or user-specific data are skipped automatically.

= Does this replace my page cache or CDN? =
No. QuantumCache operates below page caches and CDNs by reducing database and
rendering overhead. It is designed to complement, not replace, page caching
solutions.

= What happens on uninstall? =
Unless the `quantumcache_preserve_data_on_uninstall` filter returns true, QuantumCache removes its own tables and options. No wp_options or postmeta entries are left behind.

== Screenshots ==

1. Settings page showing store mode and Redis options.
2. Cache statistics and purge controls.
3. Network panel showing `X-QC-*` debug headers.

== Changelog ==

= 0.1.6 =

* Fix: Corrected QUANTUMCACHE_VERSION constant value to match plugin header (was 0.1.4).
* Compat: Fire quantumcache_loaded action after plugin init so Pro and third-party extensions can reliably detect when Free has finished bootstrapping.	

= 0.1.5 =

* Security: Hardened direct database access by validating and escaping internal
  table identifiers to satisfy PluginCheck and reviewer requirements.
* Code: Resolved all PluginCheck warnings; no functional behavior changes.
* Cleanup: Removed development-only tooling files from the release package.
* Stability: Minor internal cleanup following load testing and runtime validation.
* Fix: Corrected QUANTUMCACHE_VERSION constant value to match plugin header (was 0.1.4).
* Compat: Fire quantumcache_loaded action after plugin init so Pro and third-party
  extensions can reliably detect when Free has finished bootstrapping.

= 0.1.4 =

* Fix: Fixed incomplete Stats.php code concerning MySQL reporting
* Fix: Prefixed all global functions and variables (qc_* → quantumcache_*) to satisfy Plugin Check naming requirements.
* Fix: Updated uninstall routine to use prefixed globals and updated option names.
* Fix: Added defensive table-name validation and explicit casting in Maintenance and Stats to address Plugin Check warnings.
* Fix: Corrected several internal calls referencing the old function names (qc_should_debug_headers, etc.), preventing runtime errors.

= 0.1.3 =

* Fix: Updated MySQLStore write operations to use $wpdb->insert() with format arrays, resolving the PHPCS / reviewer-required change.
* Fix: Corrected StoreFactory to pass the required $wpdb instance when constructing MySQLStore, restoring MySQL fallback functionality.

= 0.1.2 =
* Admin: refined settings layout, help text, and capability/nonce checks.
* Code: PHPCS/WPCS compliance (sanitization, escaping, Yoda, no short ternaries).
* Store: Redis “Purge Everything” via SCAN/DEL with site prefix.
* Store: MySQL tag mapping writes via `wpdb->insert()` with formats.
* Read path: safe request URI normalization for keys and display.

= 0.1.1 =
* Fix: hydration logic in `on_posts_pre_query()` (now primes and hydrates safely).
* Perf: archive hit path uses `update_post_caches()` without taxonomy overhead.
* Safety: skip caching very small archives (fewer than 12 IDs).
* Headers: ensure `X-QC-Store-Actual` reflects real backend.

= 0.1.0 =
* Initial public release.
* Query-level caching with tag-based invalidation.
* Fragment caching for `the_content` and key blocks.
* Redis (preferred) and MySQL stores.
* Multisite support.
* Admin UI: store selection, Redis config, debug headers, purge controls, live stats.
* PHPCS clean (WordPress coding standards).

== Upgrade Notice ==

= 0.1.2 =
Admin refinements, PHPCS compliance, Redis purge, and safer URI handling.

== Privacy ==

QuantumCache does not collect, send, or log personal data.  
It stores cache entries in Redis or its own MySQL tables.  
Other plugins on your site may handle cookies or data independently.
No remote requests are made, and no data is transmitted to external servers.
