PHPackages                             alleyinteractive/wp-page-cache-control - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Caching](/categories/caching)
4. /
5. alleyinteractive/wp-page-cache-control

ActiveWordpress-plugin[Caching](/categories/caching)

alleyinteractive/wp-page-cache-control
======================================

Control and modify the page cache for multiple hosting providers.

v0.1.3(2y ago)33.4k[3 issues](https://github.com/alleyinteractive/wp-page-cache-control/issues)[9 PRs](https://github.com/alleyinteractive/wp-page-cache-control/pulls)GPL-2.0-or-laterPHPPHP ^8.0CI failing

Since Aug 3Pushed 6mo ago18 watchersCompare

[ Source](https://github.com/alleyinteractive/wp-page-cache-control)[ Packagist](https://packagist.org/packages/alleyinteractive/wp-page-cache-control)[ Docs](https://github.com/alleyinteractive/wp-page-cache-control)[ RSS](/packages/alleyinteractive-wp-page-cache-control/feed)WikiDiscussions develop Synced 3d ago

READMEChangelog (4)Dependencies (5)Versions (17)Used By (0)

WP Page Cache Control
=====================

[](#wp-page-cache-control)

[![Coding Standards](https://github.com/alleyinteractive/wp-page-cache-control/actions/workflows/coding-standards.yml/badge.svg)](https://github.com/alleyinteractive/wp-page-cache-control/actions/workflows/coding-standards.yml)[![Testing Suite](https://github.com/alleyinteractive/wp-page-cache-control/actions/workflows/unit-test.yml/badge.svg)](https://github.com/alleyinteractive/wp-page-cache-control/actions/workflows/unit-test.yml)

Control and modify the page cache for multiple hosting providers.

Installation
------------

[](#installation)

You can install the package via Composer:

```
composer require alleyinteractive/wp-page-cache-control
```

The plugin supports the following hosting providers and their respective page caching systems:

- [Pantheon](https://pantheon.io/) via [their `Pantheon Advanced Cache`plugin](https://github.com/pantheon-systems/pantheon-advanced-page-cache): (`Alley\WP\WP_Page_Cache_Control\Providers\Pantheon_Provider`)
- [WordPress VIP](https://vip.wordpress.com/) via [their `mu-plugins` repository](https://github.com/automattic/vip-go-mu-plugins/): (`Alley\WP\WP_Page_Cache_Control\Providers\VIP_Provider`)

The plugin will attempt to detect the caching system in use and will load the appropriate provider class. It can also be controlled by the `wp_page_cache_control_provider` hook which should return a provider class string.

The main goal of the plugin is to solve common page cache control needs across multiple hosting providers. It is not meant to be a complete solution for all page cache control needs. If you have a need that is not met by the plugin, please open an issue or pull request.

Usage
-----

[](#usage)

The plugin supports back-end page cache control including TTL, bypassing the page cache, user segmentation, and purging from the page cache. It also supports front-end segmentation.

Usage: Back-end
---------------

[](#usage-back-end)

Activate the plugin in WordPress and use the following methods as needed:

### Controlling the Time-to-live (TTL) of the Current Request

[](#controlling-the-time-to-live-ttl-of-the-current-request)

```
wp_page_cache_control()->ttl( 3600 );
```

### Disabling the Page Cache for the Current Request

[](#disabling-the-page-cache-for-the-current-request)

```
wp_page_cache_control()->disable_cache();
```

### Disabling the Page Cache for the Current User

[](#disabling-the-page-cache-for-the-current-user)

Disabling the page cache for the current user will cause the user to bypass the page cache for the current and subsequent requests. This is useful for testing or for logged-in users.

```
wp_page_cache_control()->disable_cache_for_user();

// enabling it again via:
wp_page_cache_control()->enable_cache_for_user();
```

### Segmenting the Page Cache

[](#segmenting-the-page-cache)

See [Page Cache Segmentation](#page-cache-segmentation) for more information.

```
wp_page_cache_control()->register_group( 'special-user-group' );

// Add the current user to the group (only needs to be done once).
wp_page_cache_control()->set_group_for_user( 'special-user-group', 'segment' );
```

### Purging a Specific URL

[](#purging-a-specific-url)

```
wp_page_cache_control()->purge( home_url( '/example/' );
```

### Purging for a Post or Term

[](#purging-for-a-post-or-term)

```
wp_page_cache_control()->purge_post( $post_id );

wp_page_cache_control()->purge_term( $term_id );
```

### Purging the Entire Page Cache

[](#purging-the-entire-page-cache)

**Warning:** This will purge the entire page cache. This is a dangerous operation and should be used with caution.

```
wp_page_cache_control()->flush();
```

Page Cache Segmentation
-----------------------

[](#page-cache-segmentation)

Page Cache Segmentation is used when you want to vary or differ the page response to different users. For example, you may want to show a different version of a page to logged-in users than to logged-out users. Or you may want to hide ads for users from a specific country. Segmenting the page cache allows you to do this in a performant way.

### Registering a Group

[](#registering-a-group)

To register a group, use the `register_group()` method:

```
wp_page_cache_control()->register_group( 'special-user-group' );
```

Group names must be unique and must contain alphanumeric characters, dashes, and underscores only.

### Adding a User to a Group

[](#adding-a-user-to-a-group)

To add a user to a group, use the `set_group_for_user()` method:

```
wp_page_cache_control()->set_group_for_user( 'special-user-group', 'segment' );
```

The second parameter allows you to specify a segment within a group. For example, the group could be "logged-in" and the segment could be "digital subscriber". You could also have a different user in the "logged-in" group with the segment "print subscriber" to show a different version of the page to print subscribers.

**Note:** A user cannot be removed from a group once added at this time. If you need to remove a user from a group, you can add them to a different segment of the same group.

### Checking if a User is in a Group or Segment

[](#checking-if-a-user-is-in-a-group-or-segment)

To check if a user is in a group or segment, use the `is_user_in_group()` method:

```
wp_page_cache_control()->is_user_in_group( 'special-user-group' );

wp_page_cache_control()->is_user_in_group( 'special-user-group', 'segment' );
```

### Testing Headers

[](#testing-headers)

The plugin supports faking the sending of headers sent through the plugin for testing purposes. To enable this, call the following code:

```
use Alley\WP\WP_Page_Cache_Control\Header;

Header::fake();
```

Once enabled, you can use the following methods to test headers being sent with the `Alley\WP\WP_Page_Cache_Control\Concerns\Tests_Headers` trait:

```
namespace Alley\WP\My_Plugin\Tests;

use Alley\WP\WP_Page_Cache_Control\Concerns\Tests_Headers;
use Alley\WP\WP_Page_Cache_Control\Header;
use Mantle\Testkit\Test_Case;

class Example_Test extends Test_Case {
	use Tests_Headers;

	protected function setUp(): void {
		parent::setUp();

		Header::fake();
	}

	public function test_example() {
		// Perform some action that should send a header.

		static::assertHeaderSent( 'X-My-Header', 'optional value' );
		static::assertHeaderNotSent( 'X-My-Other-Header', 'optional value' );

		// static::assertAnyHeadersSent() and static::assertNoHeadersSent()
		// are also available to assert that any headers were sent or not sent.
	}
}
```

Usage: Front-end
----------------

[](#usage-front-end)

The package has a front-end integration to allow for segmenting the page cache in-browser. This is enabled by default but can be disabled by using the `wp_page_cache_control_enqueue_script` filter.

Cache segmentation groups must be registered on the back end before they can be used on the front end. See [Registering a Group](#registering-a-group) for more information.

```
wpPageCacheControl.setGroupForUser('logged-in-group', 'segment-name');

// To remove a user from a group, you have to set them to a different segment.
wpPageCacheControl.setGroupForUser('logged-in-group', 'different-name');

// To check if a user is in a group or segment, use the following:
wpPageCacheControl.isUserInGroup('logged-in-group');
wpPageCacheControl.isUserInGroupSegment('logged-in-group', 'segment-name');

// You can read the groups and segments from the page cache control object:\
//
//   wpPageCacheControl.groups;
```

Types are available for TypeScript users:

```
npm install --save-dev @alleyinteractive/wp-page-cache-control

```

Testing
-------

[](#testing)

Run `npm run test` to run Jest tests against JavaScript files. Run `npm run test:watch` to keep the test runner open and watching for changes.

Run `npm run lint` to run ESLint against all JavaScript files. Linting will also happen when running development or production builds.

Run `composer test` to run tests against PHPUnit and the PHP code in the plugin.

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Credits
-------

[](#credits)

This project is actively maintained by [Alley Interactive](https://github.com/alleyinteractive). Like what you see? [Come work with us](https://alley.com/careers/).

- [Sean Fisher](https://github.com/srtfisher)
- [All Contributors](../../contributors)

License
-------

[](#license)

The GNU General Public License (GPL) license. Please see [License File](LICENSE) for more information.

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance26

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~73 days

Total

4

Last Release

846d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/338d27065b1074f2d66d049d742f22996dd137eef6f91bc8f75350ceee1e8ef2?d=identicon)[srtfisher](/maintainers/srtfisher)

---

Top Contributors

[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (83 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (83 commits)")[![srtfisher](https://avatars.githubusercontent.com/u/346399?v=4)](https://github.com/srtfisher "srtfisher (59 commits)")

---

Tags

wordpresswordpress-pluginalleyinteractivewp-page-cache-control

### Embed Badge

![Health badge](/badges/alleyinteractive-wp-page-cache-control/health.svg)

```
[![Health](https://phpackages.com/badges/alleyinteractive-wp-page-cache-control/health.svg)](https://phpackages.com/packages/alleyinteractive-wp-page-cache-control)
```

###  Alternatives

[alleyinteractive/wp-block-converter

Convert HTML into Gutenberg Blocks with PHP

65422.1k2](/packages/alleyinteractive-wp-block-converter)[alleyinteractive/wp-404-caching

Full Page Cache for WordPress 404s

12335.4k](/packages/alleyinteractive-wp-404-caching)[alleyinteractive/feed-consumer

Ingest external feeds and other data sources into WordPress

116.3k](/packages/alleyinteractive-feed-consumer)[alleyinteractive/wp-curate

Plugin to curate homepages and other landing pages

11235.0k](/packages/alleyinteractive-wp-curate)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
