=== NiroCache ===
Contributors: easycommerce
Tags: cache, page cache, performance, speed, static html
Requires at least: 6.0
Tested up to: 7.1
Requires PHP: 7.4
Stable tag: 0.9
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Static HTML page caching that works right after activation, with safe defaults, smart purging and a one-click cache test.

== Description ==

NiroCache makes your site faster by saving each page as a static HTML file and serving that file to visitors before WordPress even loads. Pages that took hundreds of milliseconds to build are delivered in a few.

It works the moment you activate it. There are no presets to study and no settings you have to change: sensible, safe defaults are already in place.

= How it works =

1. The first visitor to a page gets it generated by WordPress as usual. NiroCache saves a copy in `wp-content/cache/nirocache/`.
2. Every following visitor who is not logged in gets that copy straight from the early-cache file, skipping PHP templates and database queries.
3. When you update content, NiroCache clears exactly the pages that show it, so visitors never see outdated content.

= Features =

* Static HTML page cache served before WordPress loads.
* Smart purging: updating a post clears the post, the home page, its category and tag archives, its author archive and its post type archive. Approved comments and WooCommerce stock changes clear the affected product or post.
* Site-wide purging after theme, menu, widget, Customizer, Site Editor, permalink and general settings changes.
* Safe by default. These are never cached: logged-in users, commenters, carts, checkout and account pages, search results, previews, password-protected content, 404 pages, feeds, REST API, AJAX and form submissions. Pages that set `DONOTCACHEPAGE` or send `Cache-Control: no-cache`, `no-store` or `private` are respected.
* Tracking parameters such as `utm_source`, `gclid` and `fbclid` share the page's cached copy instead of creating new ones.
* Exclusions: never cache chosen URLs (with `*` wildcards), visitors carrying chosen cookies, or single pages ticked "Don't cache this page" in the editor.
* One-click cache test that confirms pages are stored and served, or tells you exactly why they are not.
* Detects other active page cache plugins and warns about running two page caches at once.
* Clear the cache from the admin toolbar, the settings screen, or the post editor.
* Configurable cache lifespan, plus a daily cleanup of expired pages.
* Optional debug headers (`X-Niro-Cache: HIT`, `MISS` or `BYPASS`) for troubleshooting.
* Multisite compatible: each site's cache is kept separate.
* No external services, no tracking, no ads.

= What NiroCache changes on your site =

Page caching in WordPress needs two things outside the plugin folder. NiroCache sets them up for you and removes only what it added:

* **`wp-content/advanced-cache.php`**: the standard WordPress early-cache file, copied from the plugin. It is only created if no other plugin owns it, and it is removed when you deactivate NiroCache.
* **`define( 'WP_CACHE', true );` in `wp-config.php`**: added only if WP_CACHE is not already defined, and removed when you deactivate NiroCache. If `wp-config.php` is not writable, the settings screen tells you which line to add.

Cached pages are stored in `wp-content/cache/nirocache/`. That directory holds data only: rendered HTML, a small JSON settings file per site, and empty marker files. NiroCache reads them as data and never executes anything it writes there. They are deleted when you deactivate the plugin, and the whole directory is removed when you delete the plugin.

= Privacy =

NiroCache does not collect or send any data. The cache test makes two requests from your server to your own home page and nowhere else. Cached copies only ever contain pages as seen by visitors who are not logged in.

= For developers =

Filters:

* `nirocache_should_cache` — return false to keep a rendered page dynamic.
* `nirocache_excluded_urls` — URL path patterns that are never cached.
* `nirocache_bypass_cookies` — cookie name prefixes that make a visitor bypass the cache.
* `nirocache_ignored_query_params` — query parameters that share the cached copy.
* `nirocache_post_purge_urls` — URLs cleared when a post changes.
* `nirocache_site_wide_post_types` — post types whose changes clear the whole cache.
* `nirocache_conflicting_plugins` — page cache plugins to warn about.
* `nirocache_dropin_path` and `nirocache_wp_config_path` — file locations NiroCache manages.

Actions:

* `nirocache_cache_created` — a page was stored.
* `nirocache_url_purged` — a URL's cached copies were cleared.
* `nirocache_cache_purged` — the whole cache was cleared.
* `nirocache_exclusions_changed` — a page was ticked or unticked "Don't cache this page".

Set the `NIROCACHE_CACHE_DIR` constant in `wp-config.php` to store cached pages somewhere else.

== Installation ==

1. In your dashboard, go to **Plugins > Add New Plugin**, search for "NiroCache", then click **Install Now**. Or upload the `nirocache` folder to `/wp-content/plugins/`.
2. Activate the plugin. Caching starts immediately.
3. Open **NiroCache** in the admin menu to see the cache status and click **Run cache test**.

If the status says WP_CACHE is off because `wp-config.php` is not writable, add this line near the top of `wp-config.php`, above the line that says "That's all, stop editing!":

`define( 'WP_CACHE', true );`

== Frequently Asked Questions ==

= Why don't I see cached pages while I'm logged in? =

Logged-in users always get freshly generated pages, so nobody ever sees someone else's personalised content. Click **Run cache test** on the NiroCache screen, or open your site in a private browser window, to see what visitors get.

= How do I know caching is working? =

Click **Run cache test** on the NiroCache screen. It requests your home page twice and reports whether the second request was served from the cache, or why it was not. You can also turn on **Debug headers** and look for `X-Niro-Cache: HIT` in your browser's developer tools while logged out.

= Does it work with WooCommerce? =

Yes. Cart, checkout and account pages are never cached, visitors with items in their cart always get fresh pages, and product pages are cleared when their stock changes. Easy Digital Downloads checkout pages are excluded too.

= Which web servers are supported? =

Any server that runs WordPress: Apache, Nginx, LiteSpeed and others. NiroCache uses the standard WordPress early-cache file, so no server configuration is needed.

= Can I use it together with another caching plugin? =

Running two page caches at once causes unexpected behavior, so NiroCache warns you when it detects one. Deactivate the other plugin's page cache, or turn off NiroCache's page cache. NiroCache never overwrites another plugin's `advanced-cache.php`.

= How do I exclude a page from the cache? =

Tick **Don't cache this page** in the NiroCache box of the page editor, or add its path under **Exclusions > Never cache these URLs** on the NiroCache screen. Use `/members/*` to exclude a section and everything below it.

= Forms on my site say the link has expired. =

WordPress form security tokens expire after 12 to 24 hours. Keep the cache lifespan at 10 hours (the default) or lower on sites with forms.

= How long are pages cached? =

10 hours by default. Updating content clears the affected pages immediately, so the lifespan only matters for changes NiroCache cannot detect. You can choose from 1 hour to 7 days, or never expire.

= What happens when I deactivate or delete NiroCache? =

Deactivating removes the early-cache file and the `WP_CACHE` line NiroCache added, and deletes cached pages; your settings are kept. Deleting the plugin also removes its settings and the whole cache directory.

== Changelog ==

= 0.9 =
* The early-cache file `wp-content/advanced-cache.php` is now copied from a file that ships with the plugin instead of being generated. NiroCache no longer writes PHP anywhere.
* The settings screen now reports when the plugin folder has been renamed, which stops the early-cache file from finding NiroCache.

= 0.8.1 =
* The cache test token is now stored as a hash, so the runtime config file holds no secret.

= 0.8 =
* Initial release.
