PHPackages                             dwnload/wp-rest-api-object-cache - 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. dwnload/wp-rest-api-object-cache

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

dwnload/wp-rest-api-object-cache
================================

Enable object caching for WordPress' REST API. Aids in increased response times of your applications endpoints.

1.4.0(7y ago)237192[1 issues](https://github.com/dwnload/wp-rest-api-object-cache/issues)MITPHPPHP &gt;=7.0.4CI failing

Since Feb 14Pushed 4mo ago2 watchersCompare

[ Source](https://github.com/dwnload/wp-rest-api-object-cache)[ Packagist](https://packagist.org/packages/dwnload/wp-rest-api-object-cache)[ RSS](/packages/dwnload-wp-rest-api-object-cache/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (10)Dependencies (4)Versions (16)Used By (0)

WordPress REST API Object Cache
===============================

[](#wordpress-rest-api-object-cache)

![PHP from Packagist](https://camo.githubusercontent.com/f9a11b77798c4541006892f4338709cf28abb90e71882850f33e1ce83d55adbc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f64776e6c6f61642f77702d726573742d6170692d6f626a6563742d63616368652e737667)[![Latest Stable Version](https://camo.githubusercontent.com/ff48cd166f5fc5b7a420036d477c2ec9d256a7f5157b906bc92ed377d5707f8a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f64776e6c6f61642f77702d726573742d6170692d6f626a6563742d63616368652e737667)](https://packagist.org/packages/dwnload/wp-rest-api-object-cache)[![Total Downloads](https://camo.githubusercontent.com/cebab14cdb9d70324ecd3880bae8f87db4e156aa0c68efba6b0f7e5eb40bcdc2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f64776e6c6f61642f77702d726573742d6170692d6f626a6563742d63616368652e737667)](https://packagist.org/packages/dwnload/wp-rest-api-object-cache)[![License](https://camo.githubusercontent.com/6c6db461a25fca184576b03dce81de198e6696ebdf962d3d6f1893c577000f6c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f64776e6c6f61642f77702d726573742d6170692d6f626a6563742d63616368652e737667)](https://packagist.org/packages/dwnload/wp-rest-api-object-cache)

Enable object caching for WordPress' REST API. Aids in increased response times of your applications endpoints.

Package Installation (via Composer)
-----------------------------------

[](#package-installation-via-composer)

To install this package, edit your `composer.json` file:

```
{
    "require": {
        "dwnload/wp-rest-api-object-cache": "^1.3.0"
    }
}
```

Now run:

`$ composer install dwnload/wp-rest-api-object-cache`

---

- [Actions](#actions)
- [How to use actions](#how-to-use-actions)
- [Filters](#filters)
- [How to use filters](#how-to-use-filters)

Actions
=======

[](#actions)

ActionArgument(s)Dwnload\\WpRestApi\\RestApi\\RestDispatch::ACTION\_CACHE\_SKIPPEDmixed **$result**
WP\_REST\_Server **$server**
WP\_REST\_Request **$request**Dwnload\\WpRestApi\\WpAdmin\\Admin::ACTION\_REQUEST\_FLUSH\_CACHEstring **$message**
string **$type**
WP\_User **$user**How to use actions
------------------

[](#how-to-use-actions)

```
use Dwnload\WpRestApi\RestApi\RestDispatch;
add_action( RestDispatch::ACTION_CACHE_SKIPPED, function( $result, \WP_REST_Server $server, \WP_REST_Request $request ) {
	// Do something here, like create a log entry using Wonolog.
}, 10, 3 );
```

```
use Dwnload\WpRestApi\WpAdmin\Admin;
add_action( Admin::ACTION_REQUEST_FLUSH_CACHE, function( $message, $type, WP_User $user ) {
	// Do something here, like create a log entry using Wonolog.
}, 10, 3 );
```

Filters
=======

[](#filters)

FilterArgument(s)Dwnload\\WpRestApi\\RestApi\\RestDispatch::FILTER\_CACHE\_HEADERSarray **$headers**
string **$request\_uri**
WP\_REST\_Server **$server**
WP\_REST\_Request **$request**
WP\_REST\_Response **$response (`rest_pre_dispatch` only)**Dwnload\\WpRestApi\\RestApi\\RestDispatch::FILTER\_CACHE\_SKIPboolean **$skip** ( default: WP\_DEBUG )
string **$request\_uri**
WP\_REST\_Server **$server**
WP\_REST\_Request **$request**Dwnload\\WpRestApi\\RestApi\\RestDispatch::FILTER\_API\_KEYstring **$request\_uri**
WP\_REST\_Server **$server**
WP\_REST\_Request **$request**Dwnload\\WpRestApi\\RestApi\\RestDispatch::FILTER\_API\_GROUPstring **$cache\_group**Dwnload\\WpRestApi\\RestApi\\RestDispatch::FILTER\_CACHE\_EXPIREint **$expires**Dwnload\\WpRestApi\\WpAdmin\\Admin::FILTER\_CACHE\_UPDATE\_OPTIONSarray **$options**Dwnload\\WpRestApi\\WpAdmin\\Admin::FILTER\_CACHE\_OPTIONSarray **$options**Dwnload\\WpRestApi\\WpAdmin\\Admin::FILTER\_SHOW\_ADMINboolean **$show**Dwnload\\WpRestApi\\WpAdmin\\Admin::FILTER\_SHOW\_ADMIN\_MENUboolean **$show**Dwnload\\WpRestApi\\WpAdmin\\Admin::FILTER\_SHOW\_ADMIN\_BAR\_MENUboolean **$show**Dwnload\\WpRestApi\\RestApi\\RestDispatch::FILTER\_ALLOWED\_CACHE\_STATUSarray **$status** HTTP Header statuses (defaults to `array( 200 )`Dwnload\\WpRestApi\\RestApi\\RestDispatch::FILTER\_CACHE\_VALIDATE\_AUTHboolean **$authenticated**
WP\_REST\_Request $requestHow to use filters
------------------

[](#how-to-use-filters)

**Sending headers.**

```
use Dwnload\WpRestApi\RestApi\RestDispatch;
add_filter( RestDispatch::FILTER_CACHE_HEADERS, function( array $headers ) : array {
	$headers['Cache-Control'] = 'public, max-age=3600';

	return $headers;
} );
```

**Changing the cache expire time.**

```
use Dwnload\WpRestApi\RestApi\RestDispatch;
add_filter( RestDispatch::FILTER_CACHE_EXPIRE, function() : int {
	// https://codex.wordpress.org/Transients_API#Using_Time_Constants
	return ( HOUR_IN_SECONDS * 5 );
} );
```

```
use Dwnload\WpRestApi\WpAdmin\Admin;
add_filter( Admin::FILTER_CACHE_OPTIONS, function( array $options ) : array {
	if ( ! isset( $options['timeout'] ) ) {
		$options['timeout'] = array();
	}

	// https://codex.wordpress.org/Transients_API#Using_Time_Constants
	$options['timeout']['length'] = 15;
	$options['timeout']['period'] = DAY_IN_SECONDS;

	return $options;
} );
```

**Validating user auth when `?context=edit`**

```
use Dwnload\WpRestApi\RestApi\RestDispatch;
add_filter( RestDispatch::FILTER_CACHE_VALIDATE_AUTH, function( bool $auth, WP_REST_Request $request ) : bool {
	// If you are running the Basic Auth plugin.
	if ( $GLOBALS['wp_json_basic_auth_error'] === true ) {
        $authorized = true;
    }
    // Otherwise, maybe do some additional logic on the request for current user...

    return $authorized;
}, 10, 2 );
```

**Skipping cache**

```
use Dwnload\WpRestApi\RestApi\RestDispatch;
add_filter( RestDispatch::FILTER_CACHE_SKIP, function( bool $skip, string $request_uri ) : bool {
	if ( ! $skip && stripos( 'wp-json/dwnload/v2', $request_uri ) !== false ) {
		return true;
	}

	return $skip;
}, 10, 2 );
```

**Deleting cache**

*Soft delete:*Append `RestDispatch::QUERY_CACHE_DELETE` to your query param: `add_query_arg( [ RestDispatch::QUERY_CACHE_DELETE, '1' ], '' )`.
*soft delete will delete the cache after the current request completes (on WordPress shutdown).*

*Hard delete:* Append `RestDispatch::QUERY_CACHE_DELETE` &amp;&amp; `RestDispatch::QUERY_CACHE_FORCE_DELETE` to your query param: `add_query_arg( [ RestDispatch::QUERY_CACHE_DELETE, '1', RestDispatch::QUERY_CACHE_FORCE_DELETE, '1' ], '' )`.
*hard delete will delete the cache before the request, forcing it to repopulate.*

**empty ALL cache on post-save** *this is not ideal*

You can use the WordPress filter `save_post` if you would like to empty **ALL** cache on post save.

```
use Dwnload\WpRestApi\RestApi\RestDispatch;
add_action( 'save_post', function( $post_id ) {
  if ( class_exists( RestDispatch::class ) ) {
    call_user_func( [ ( WpRestApiCache::getRestDispatch(), 'wpCacheFlush' ] );
  }
} );
```

**Maybe better to use `transition_post_status`**

```
add_action( 'transition_post_status', function(  string $new_status, string $old_status, \WP_Post $post ) {
  if ( 'publish' === $new_status || 'publish' === $old_status ) {
    \wp_cache_flush();
  }
}, 99, 3 );
```

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance51

Moderate activity, may be stable

Popularity23

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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 ~30 days

Recently: every ~80 days

Total

15

Last Release

2624d ago

Major Versions

0.2.1 → 1.0.12018-04-18

### Community

Maintainers

![](https://www.gravatar.com/avatar/9297f4f4d23d5528e50d33af9d3f79bcfe7900dfdda17993be767157098f58bb?d=identicon)[thefrosty](/maintainers/thefrosty)

---

Top Contributors

[![thefrosty](https://avatars.githubusercontent.com/u/367897?v=4)](https://github.com/thefrosty "thefrosty (80 commits)")

---

Tags

object-cachewordpresswordpress-pluginwp-json

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/dwnload-wp-rest-api-object-cache/health.svg)

```
[![Health](https://phpackages.com/badges/dwnload-wp-rest-api-object-cache/health.svg)](https://phpackages.com/packages/dwnload-wp-rest-api-object-cache)
```

###  Alternatives

[wp-media/wp-rocket

Performance optimization plugin for WordPress

7491.3M3](/packages/wp-media-wp-rocket)[helsingborg-stad/municipio

A bootstrap theme for creating municipality sites.

4028.3k10](/packages/helsingborg-stad-municipio)[rhubarbgroup/redis-cache

A persistent object cache backend for WordPress powered by Redis. Supports Predis, PhpRedis, Relay, replication, sentinels, clustering and WP-CLI.

52699.8k1](/packages/rhubarbgroup-redis-cache)[pressbooks/pressbooks

Pressbooks is an open source book publishing tool built on a WordPress multisite platform. Pressbooks outputs books in multiple formats, including PDF, EPUB, web, and a variety of XML flavours, using a theming/templating system, driven by CSS.

45344.0k1](/packages/pressbooks-pressbooks)[humanmade/batcache

A memcached HTML page cache for WordPress.

17464.7k7](/packages/humanmade-batcache)[vdlp/oc-redirect-plugin

Advanced redirect plugin for October CMS.

26100.7k1](/packages/vdlp-oc-redirect-plugin)

PHPackages © 2026

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