> For the complete documentation index, see [llms.txt](https://whoisandywhite.gitbook.io/porterwp/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://whoisandywhite.gitbook.io/porterwp/features/caching.md). Agents can also search and read this documentation through its [MCP server](https://whoisandywhite.gitbook.io/porterwp/~gitbook/mcp).

# Caching and environments

PorterWP uses several small caches for different jobs. The production switch applies to theme discovery and configuration caches; it does not globally turn every short-lived operational cache on or off.

The behavior documented here applies to PorterWP 1.4.95.

## Environment behavior

`porter_can_use_cached()` returns `true` only when:

```php
wp_get_environment_type() === 'production';
```

In production, PorterWP can reuse theme configuration, block, style, and include-discovery results. Cross-request reuse through WordPress's object-cache API requires a persistent object-cache backend; the option-backed discovery caches do not. In `local`, `development`, and `staging`, those results are rebuilt rather than reused so theme work appears immediately.

Some option values are still written after a rebuild outside production. They are warm data for a later production request, but PorterWP will not trust and reuse them while the environment remains non-production.

Within-request memoization is used in every environment. It only prevents the same JSON file from being decoded repeatedly during one PHP request.

## Theme and configuration caches

| Data                           | Storage                                                                              | Reused in production when                                                                                                                                   |
| ------------------------------ | ------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Decoded `porter/config/*.json` | Object-cache group `porter_wp`, using signature-based keys                           | The active stylesheet, theme version, resolved config path, file modification time, file size, and cache generation still match. Default lifetime: one day. |
| Premium ACF block discovery    | `porter_blocks` and `porter_blocks_version` options                                  | The value is an array and the active stylesheet plus `blocks.json` version match.                                                                           |
| Custom block styles            | `porter_block_styles` and `porter_block_styles_version` options                      | The active theme, `blocks.json`, configured styles, and referenced CSS-file signature match.                                                                |
| Core block CSS fragment        | `porter_core_block_styles` and `porter_core_block_styles_version` options            | The active theme, `blocks.json`, CSS directory, and discovered CSS-file signature match.                                                                    |
| Theme PHP include list         | `porter_inc_files`, `porter_inc_directories`, and `porter_inc_files_version` options | The resolved `porter/inc` root, config, directories, files, and active theme signature match and every cached path remains safe.                            |

Valid empty arrays are cached. An empty result therefore does not force another filesystem scan on every production request.

The JSON object-cache lifetime can be changed or disabled:

```php
add_filter( 'porter_wp_settings_cache_ttl', function ( $ttl, $file, $path ) {
    if ( 'blocks.json' === $file ) {
        return 6 * HOUR_IN_SECONDS;
    }

    return $ttl;
}, 10, 3 );
```

Return `0` to skip writing that persistent JSON cache. Request-local memoization still applies.

### Invalidation

Normal edits and deployments change one or more signature inputs. Switching the active stylesheet or changing the theme version also separates cached results between themes.

The `version` value in a Porter JSON file remains a useful explicit release marker and is still used directly by block discovery. It is not the only cache invalidation signal for the other configuration and style caches.

If a deployment deliberately preserves file modification times and sizes, increment the relevant JSON `version` and use **Clear PorterWP Cache** after deployment.

The include-file cache is defensive: cached paths must resolve to readable PHP files inside the configured `porter/inc` root. A stale or unsafe list is rebuilt once, and individual unsafe entries are skipped rather than redirecting or ending AJAX, REST, cron, or CLI requests.

## Site Editor preview cache

The premium Site Editor optimizer is a separate operational cache and is not controlled by `WP_ENVIRONMENT_TYPE`:

* the browser de-duplicates eligible preview GET requests for 10 seconds by default;
* the server caches successful eligible REST responses for 30 seconds by default;
* an external object cache uses the group `porterwp_site_editor_previews`;
* without an external object cache, PorterWP uses a short-lived transient.

Entries are scoped to the site, current user, active theme, route, and sorted query parameters. See [Site Editor preview optimiser](https://whoisandywhite.gitbook.io/porterwp/features/site-editor-preview-optimiser.md) for request boundaries, invalidation, and opt-out filters.

## Premium filter transients

Premium filters use bounded transients independently of the environment:

* signed filter-schema registries are retained for at least one hour and for one week by default;
* generated meta-option values are cached for one day;
* successful UK postcode coordinates are cached for seven days;
* failed postcode lookups are cached for 15 minutes;
* postcode lookup rate counters last five minutes.

These caches support request validation and bound external work. Do not disable or bulk-delete them on every page request.

## Clearing PorterWP's theme caches

Use **WP Admin → Settings → PorterWP → Clear PorterWP Cache**. The action requires `manage_options` and a valid nonce.

The action deletes Porter's known block, style, include, and rewrite-signature options. It also increments `porter_cache_generation`, which makes all signature-based JSON object-cache keys unreachable even though those keys cannot be enumerated individually.

Clearing the rewrite signature allows the coordinated lifecycle to perform one soft rewrite flush after all providers register on a later safe browser request. See [Plugin lifecycle](https://whoisandywhite.gitbook.io/porterwp/features/plugin-lifecycle.md).

The button does not promise to delete every option or transient whose name starts with `porter_`. In particular, it does not enumerate short-lived Site Editor previews or filter security/lookup transients. Those expire according to their own bounded lifetimes.

Avoid broad database commands such as deleting every `porter_*` option. They can remove lifecycle registries or operational state that is unrelated to the theme cache. Prefer the authenticated admin action or delete only a specific, understood option while troubleshooting.

## Deployment guidance

1. Set `WP_ENVIRONMENT_TYPE` correctly for each environment.
2. Increment configuration `version` values as part of intentional theme releases, especially `blocks.json` when block folders change.
3. Let file and theme signatures handle normal edits.
4. Clear the PorterWP cache after a deployment only when metadata was preserved or a stale result is observed.
5. Do not add a routine permalink flush; rewrite signatures coordinate that work automatically.
