PHPackages                             wp-cli/cache-command - 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. [CLI &amp; Console](/categories/cli)
4. /
5. wp-cli/cache-command

ActiveWp-cli-package[CLI &amp; Console](/categories/cli)

wp-cli/cache-command
====================

Manages object and transient caches.

v2.2.2(1mo ago)167.5M↑28.4%24[1 issues](https://github.com/wp-cli/cache-command/issues)6MITPHPCI passing

Since Apr 17Pushed 2mo ago4 watchersCompare

[ Source](https://github.com/wp-cli/cache-command)[ Packagist](https://packagist.org/packages/wp-cli/cache-command)[ Docs](https://github.com/wp-cli/cache-command)[ RSS](/packages/wp-cli-cache-command/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (6)Versions (30)Used By (6)

wp-cli/cache-command
====================

[](#wp-clicache-command)

Manages object and transient caches.

[![Testing](https://github.com/wp-cli/cache-command/actions/workflows/testing.yml/badge.svg)](https://github.com/wp-cli/cache-command/actions/workflows/testing.yml)

Quick links: [Using](#using) | [Installing](#installing) | [Contributing](#contributing) | [Support](#support)

Using
-----

[](#using)

This package implements the following commands:

### wp cache

[](#wp-cache)

Adds, removes, fetches, and flushes the WP Object Cache object.

```
wp cache

```

By default, the WP Object Cache exists in PHP memory for the length of the request (and is emptied at the end). Use a persistent object cache drop-in to persist the object cache between requests.

[Read the documentation](https://developer.wordpress.org/reference/classes/wp_object_cache)for more detail.

**EXAMPLES**

```
# Set cache.
$ wp cache set my_key my_value my_group 300
Success: Set object 'my_key' in group 'my_group'.

# Get cache.
$ wp cache get my_key my_group
my_value

```

### wp cache add

[](#wp-cache-add)

Adds a value to the object cache.

```
wp cache add   [] []

```

Errors if a value already exists for the key, which means the value can't be added.

**OPTIONS**

```

	Cache key.

	Value to add to the key.

[]
	Method for grouping data within the cache which allows the same key to be used across groups.
	---
	default: default
	---

[]
	Define how long to keep the value, in seconds. `0` means as long as possible.
	---
	default: 0
	---

```

**EXAMPLES**

```
# Add cache.
$ wp cache add my_key my_value my_group 300
Success: Added object 'my_key' in group 'my_group'.

```

### wp cache decr

[](#wp-cache-decr)

Decrements a value in the object cache.

```
wp cache decr  [] []

```

Errors if the value can't be decremented.

**OPTIONS**

```

	Cache key.

[]
	The amount by which to decrement the item's value.
	---
	default: 1
	---

[]
	Method for grouping data within the cache which allows the same key to be used across groups.
	---
	default: default
	---

```

**EXAMPLES**

```
# Decrease cache value.
$ wp cache decr my_key 2 my_group
48

```

### wp cache delete

[](#wp-cache-delete)

Removes a value from the object cache.

```
wp cache delete  []

```

Errors if the value can't be deleted.

**OPTIONS**

```

	Cache key.

[]
	Method for grouping data within the cache which allows the same key to be used across groups.
	---
	default: default
	---

```

**EXAMPLES**

```
# Delete cache.
$ wp cache delete my_key my_group
Success: Object deleted.

```

### wp cache flush

[](#wp-cache-flush)

Flushes the object cache.

```
wp cache flush

```

For WordPress multisite instances using a persistent object cache, flushing the object cache will typically flush the cache for all sites. Beware of the performance impact when flushing the object cache in production.

Errors if the object cache can't be flushed.

**EXAMPLES**

```
# Flush cache.
$ wp cache flush
Success: The cache was flushed.

```

### wp cache flush-group

[](#wp-cache-flush-group)

Removes all cache items in a group, if the object cache implementation supports it.

```
wp cache flush-group

```

**OPTIONS**

```

	Cache group key.

```

**EXAMPLES**

```
# Clear cache group.
$ wp cache flush-group my_group
Success: Cache group 'my_group' was flushed.

```

### wp cache get

[](#wp-cache-get)

Gets a value from the object cache.

```
wp cache get  []

```

Errors if the value doesn't exist.

**OPTIONS**

```

	Cache key.

[]
	Method for grouping data within the cache which allows the same key to be used across groups.
	---
	default: default
	---

```

**EXAMPLES**

```
# Get cache.
$ wp cache get my_key my_group
my_value

```

### wp cache incr

[](#wp-cache-incr)

Increments a value in the object cache.

```
wp cache incr  [] []

```

Errors if the value can't be incremented.

**OPTIONS**

```

	Cache key.

[]
	The amount by which to increment the item's value.
	---
	default: 1
	---

[]
	Method for grouping data within the cache which allows the same key to be used across groups.
	---
	default: default
	---

```

**EXAMPLES**

```
# Increase cache value.
$ wp cache incr my_key 2 my_group
50

```

### wp cache patch

[](#wp-cache-patch)

Update a nested value from the cache.

```
wp cache patch   ... [] [--group=] [--expiration=] [--format=]

```

**OPTIONS**

```

	Patch action to perform.
	---
	options:
	  - insert
	  - update
	  - delete
	---

	Cache key.

...
	The name(s) of the keys within the value to locate the value to patch.

[]
	The new value. If omitted, the value is read from STDIN.

[--group=]
	Method for grouping data within the cache which allows the same key to be used across groups.
	---
	default: default
	---

[--expiration=]
	Define how long to keep the value, in seconds. `0` means as long as possible.
	---
	default: 0
	---

[--format=]
	The serialization format for the value.
	---
	default: plaintext
	options:
	  - plaintext
	  - json
	---

```

### wp cache pluck

[](#wp-cache-pluck)

Get a nested value from the cache.

```
wp cache pluck  ... [--group=] [--format=]

```

**OPTIONS**

```

	Cache key.

...
	The name(s) of the keys within the value to locate the value to pluck.

[--group=]
	Method for grouping data within the cache which allows the same key to be used across groups.
	---
	default: default
	---

[--format=]
	The output format of the value.
	---
	default: plaintext
	options:
	  - plaintext
	  - json
	  - yaml
	---

```

### wp cache replace

[](#wp-cache-replace)

Replaces a value in the object cache, if the value already exists.

```
wp cache replace   [] []

```

Errors if the value can't be replaced.

**OPTIONS**

```

	Cache key.

	Value to replace.

[]
	Method for grouping data within the cache which allows the same key to be used across groups.
	---
	default: default
	---

[]
	Define how long to keep the value, in seconds. `0` means as long as possible.
	---
	default: 0
	---

```

**EXAMPLES**

```
# Replace cache.
$ wp cache replace my_key new_value my_group
Success: Replaced object 'my_key' in group 'my_group'.

```

### wp cache set

[](#wp-cache-set)

Sets a value to the object cache, regardless of whether it already exists.

```
wp cache set   [] []

```

Errors if the value can't be set.

**OPTIONS**

```

	Cache key.

	Value to set on the key.

[]
	Method for grouping data within the cache which allows the same key to be used across groups.
	---
	default: default
	---

[]
	Define how long to keep the value, in seconds. `0` means as long as possible.
	---
	default: 0
	---

```

**EXAMPLES**

```
# Set cache.
$ wp cache set my_key my_value my_group 300
Success: Set object 'my_key' in group 'my_group'.

```

### wp cache supports

[](#wp-cache-supports)

Determines whether the object cache implementation supports a particular feature.

```
wp cache supports

```

**OPTIONS**

```

	Name of the feature to check for.

```

**EXAMPLES**

```
# Check whether is add_multiple supported.
$ wp cache supports add_multiple
$ echo $?
0

# Bash script for checking whether for support like this:
if ! wp cache supports non_existing; then
    echo 'non_existing is not supported'
fi

```

### wp cache type

[](#wp-cache-type)

Attempts to determine which object cache is being used.

```
wp cache type

```

Note that the guesses made by this function are based on the WP\_Object\_Cache classes that define the 3rd party object cache extension. Changes to those classes could render problems with this function's ability to determine which object cache is being used.

**EXAMPLES**

```
# Check cache type.
$ wp cache type
Default

```

### wp transient

[](#wp-transient)

Adds, gets, and deletes entries in the WordPress Transient Cache.

```
wp transient

```

By default, the transient cache uses the WordPress database to persist values between requests. On a single site installation, values are stored in the `wp_options` table. On a multisite installation, values are stored in the `wp_options` or the `wp_sitemeta` table, depending on use of the `--network`flag.

When a persistent object cache drop-in is installed (e.g. Redis or Memcached), the transient cache skips the database and simply wraps the WP Object Cache.

**EXAMPLES**

```
# Set transient.
$ wp transient set sample_key "test data" 3600
Success: Transient added.

# Get transient.
$ wp transient get sample_key
test data

# Delete transient.
$ wp transient delete sample_key
Success: Transient deleted.

# Delete expired transients.
$ wp transient delete --expired
Success: 12 expired transients deleted from the database.

# Delete all transients.
$ wp transient delete --all
Success: 14 transients deleted from the database.

# Delete all site transients.
$ wp transient delete --all --network
Success: 2 transients deleted from the database.

```

### wp transient delete

[](#wp-transient-delete)

Deletes a transient value.

```
wp transient delete [] [--network] [--all] [--expired]

```

For a more complete explanation of the transient cache, including the network|site cache, please see docs for `wp transient`.

**OPTIONS**

```
[]
	Key for the transient.

[--network]
	Delete the value of a network|site transient. On single site, this is
	is a specially-named cache key. On multisite, this is a global cache
	(instead of local to the site).

[--all]
	Delete all transients.

[--expired]
	Delete all expired transients.

```

**EXAMPLES**

```
# Delete transient.
$ wp transient delete sample_key
Success: Transient deleted.

# Delete expired transients.
$ wp transient delete --expired
Success: 12 expired transients deleted from the database.

# Delete expired site transients.
$ wp transient delete --expired --network
Success: 1 expired transient deleted from the database.

# Delete all transients.
$ wp transient delete --all
Success: 14 transients deleted from the database.

# Delete all site transients.
$ wp transient delete --all --network
Success: 2 transients deleted from the database.

# Delete all transients in a multisite.
$ wp transient delete --all --network && wp site list --field=url | xargs -n1 -I % wp --url=% transient delete --all

```

### wp transient get

[](#wp-transient-get)

Gets a transient value.

```
wp transient get  [--format=] [--network]

```

For a more complete explanation of the transient cache, including the network|site cache, please see docs for `wp transient`.

**OPTIONS**

```

	Key for the transient.

[--format=]
	Render output in a particular format.
	---
	default: table
	options:
	  - table
	  - csv
	  - json
	  - yaml
	---

[--network]
	Get the value of a network|site transient. On single site, this is
	is a specially-named cache key. On multisite, this is a global cache
	(instead of local to the site).

```

**EXAMPLES**

```
$ wp transient get sample_key
test data

$ wp transient get random_key
Warning: Transient with key "random_key" is not set.

```

### wp transient list

[](#wp-transient-list)

Lists transients and their values.

```
wp transient list [--search=] [--exclude=] [--network] [--unserialize] [--human-readable] [--fields=] [--format=]

```

**OPTIONS**

```
[--search=]
	Use wildcards ( * and ? ) to match transient name.

[--exclude=]
	Pattern to exclude. Use wildcards ( * and ? ) to match transient name.

[--network]
	Get the values of network|site transients. On single site, this is
	a specially-named cache key. On multisite, this is a global cache
	(instead of local to the site).

[--unserialize]
	Unserialize transient values in output.

[--human-readable]
	Human-readable output for expirations.

[--fields=]
	Limit the output to specific object fields.

[--format=]
	The serialization format for the value.
	---
	default: table
	options:
	  - table
	  - json
	  - csv
	  - count
	  - yaml
	---

```

**AVAILABLE FIELDS**

This field will be displayed by default for each matching option:

- name
- value
- expiration

**EXAMPLES**

```
# List all transients
$ wp transient list
 +------+-------+---------------+
 | name | value | expiration    |
 +------+-------+---------------+
 | foo  | bar   | 39 mins       |
 | foo2 | bar2  | no expiration |
 | foo3 | bar2  | expired       |
 | foo4 | bar4  | 4 hours       |
 +------+-------+---------------+

```

### wp transient patch

[](#wp-transient-patch)

Update a nested value from a transient.

```
wp transient patch   ... [] [--format=] [--expiration=] [--network]

```

**OPTIONS**

```

	Patch action to perform.
	---
	options:
	  - insert
	  - update
	  - delete
	---

	Key for the transient.

...
	The name(s) of the keys within the value to locate the value to patch.

[]
	The new value. If omitted, the value is read from STDIN.

[--format=]
	The serialization format for the value.
	---
	default: plaintext
	options:
	  - plaintext
	  - json
	---

[--expiration=]
	Time until expiration, in seconds.
	---
	default: 0
	---

[--network]
	Get the value of a network|site transient. On single site, this is
	a specially-named cache key. On multisite, this is a global cache
	(instead of local to the site).

```

### wp transient pluck

[](#wp-transient-pluck)

Get a nested value from a transient.

```
wp transient pluck  ... [--format=] [--network]

```

**OPTIONS**

```

	Key for the transient.

...
	The name(s) of the keys within the value to locate the value to pluck.

[--format=]
	The output format of the value.
	---
	default: plaintext
	options:
	  - plaintext
	  - json
	  - yaml
	---

[--network]
	Get the value of a network|site transient. On single site, this is
	a specially-named cache key. On multisite, this is a global cache
	(instead of local to the site).

```

### wp transient set

[](#wp-transient-set)

Sets a transient value.

```
wp transient set   [] [--network]

```

`` is the time until expiration, in seconds.

For a more complete explanation of the transient cache, including the network|site cache, please see docs for `wp transient`.

**OPTIONS**

```

	Key for the transient.

	Value to be set for the transient.

[]
	Time until expiration, in seconds.

[--network]
	Set the value of a network|site transient. On single site, this is
	is a specially-named cache key. On multisite, this is a global cache
	(instead of local to the site).

```

**EXAMPLES**

```
$ wp transient set sample_key "test data" 3600
Success: Transient added.

```

### wp transient type

[](#wp-transient-type)

Determines the type of transients implementation.

```
wp transient type

```

Indicates whether the transients API is using an object cache or the database.

For a more complete explanation of the transient cache, including the network|site cache, please see docs for `wp transient`.

**EXAMPLES**

```
$ wp transient type
Transients are saved to the database.

```

Installing
----------

[](#installing)

This package is included with WP-CLI itself, no additional installation necessary.

To install the latest version of this package over what's included in WP-CLI, run:

```
wp package install git@github.com:wp-cli/cache-command.git

```

Contributing
------------

[](#contributing)

We appreciate you taking the initiative to contribute to this project.

Contributing isn’t limited to just code. We encourage you to contribute in the way that best fits your abilities, by writing tutorials, giving a demo at your local meetup, helping other users with their support questions, or revising our documentation.

For a more thorough introduction, [check out WP-CLI's guide to contributing](https://make.wordpress.org/cli/handbook/contributing/). This package follows those policy and guidelines.

### Reporting a bug

[](#reporting-a-bug)

Think you’ve found a bug? We’d love for you to help us get it fixed.

Before you create a new issue, you should [search existing issues](https://github.com/wp-cli/cache-command/issues?q=label%3Abug%20) to see if there’s an existing resolution to it, or if it’s already been fixed in a newer version.

Once you’ve done a bit of searching and discovered there isn’t an open or fixed issue for your bug, please [create a new issue](https://github.com/wp-cli/cache-command/issues/new). Include as much detail as you can, and clear steps to reproduce if possible. For more guidance, [review our bug report documentation](https://make.wordpress.org/cli/handbook/bug-reports/).

### Creating a pull request

[](#creating-a-pull-request)

Want to contribute a new feature? Please first [open a new issue](https://github.com/wp-cli/cache-command/issues/new) to discuss whether the feature is a good fit for the project.

Once you've decided to commit the time to seeing your pull request through, [please follow our guidelines for creating a pull request](https://make.wordpress.org/cli/handbook/pull-requests/) to make sure it's a pleasant experience. See "[Setting up](https://make.wordpress.org/cli/handbook/pull-requests/#setting-up)" for details specific to working on this package locally.

Support
-------

[](#support)

GitHub issues aren't for general support questions, but there are other venues you can try:

*This README.md is generated dynamically from the project's codebase using `wp scaffold package-readme` ([doc](https://github.com/wp-cli/scaffold-package-command#wp-scaffold-package-readme)). To suggest changes, please submit a pull request against the corresponding part of the codebase.*

###  Health Score

66

—

FairBetter than 99% of packages

Maintenance87

Actively maintained with recent releases

Popularity56

Moderate usage in the ecosystem

Community35

Small or concentrated contributor base

Maturity74

Established project with proven stability

 Bus Factor1

Top contributor holds 50.9% 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 ~130 days

Recently: every ~201 days

Total

26

Last Release

53d ago

Major Versions

v1.0.6 → v2.0.02018-08-05

### Community

Maintainers

![](https://www.gravatar.com/avatar/4b5740d002b5556abcceed36e016c8f8ba6f533eefef6107b3c60a830704993b?d=identicon)[danielbachhuber](/maintainers/danielbachhuber)

![](https://www.gravatar.com/avatar/6dde7f578e5530884238e7173f768ae3a890b6d66eb99262a82f2c494a1b67d4?d=identicon)[schlessera](/maintainers/schlessera)

---

Top Contributors

[![danielbachhuber](https://avatars.githubusercontent.com/u/36432?v=4)](https://github.com/danielbachhuber "danielbachhuber (554 commits)")[![scribu](https://avatars.githubusercontent.com/u/225715?v=4)](https://github.com/scribu "scribu (166 commits)")[![schlessera](https://avatars.githubusercontent.com/u/83631?v=4)](https://github.com/schlessera "schlessera (134 commits)")[![swissspidy](https://avatars.githubusercontent.com/u/841956?v=4)](https://github.com/swissspidy "swissspidy (49 commits)")[![ocean90](https://avatars.githubusercontent.com/u/617637?v=4)](https://github.com/ocean90 "ocean90 (34 commits)")[![petitphp](https://avatars.githubusercontent.com/u/158572?v=4)](https://github.com/petitphp "petitphp (28 commits)")[![ernilambar](https://avatars.githubusercontent.com/u/2098823?v=4)](https://github.com/ernilambar "ernilambar (24 commits)")[![szepeviktor](https://avatars.githubusercontent.com/u/952007?v=4)](https://github.com/szepeviktor "szepeviktor (8 commits)")[![NateWr](https://avatars.githubusercontent.com/u/2306629?v=4)](https://github.com/NateWr "NateWr (8 commits)")[![miya0001](https://avatars.githubusercontent.com/u/309946?v=4)](https://github.com/miya0001 "miya0001 (7 commits)")[![mattheu](https://avatars.githubusercontent.com/u/494927?v=4)](https://github.com/mattheu "mattheu (7 commits)")[![ako80218](https://avatars.githubusercontent.com/u/5031441?v=4)](https://github.com/ako80218 "ako80218 (7 commits)")[![mwilliamson](https://avatars.githubusercontent.com/u/391876?v=4)](https://github.com/mwilliamson "mwilliamson (6 commits)")[![jrfnl](https://avatars.githubusercontent.com/u/663378?v=4)](https://github.com/jrfnl "jrfnl (5 commits)")[![nyordanov](https://avatars.githubusercontent.com/u/192220?v=4)](https://github.com/nyordanov "nyordanov (5 commits)")[![janw-me](https://avatars.githubusercontent.com/u/1026882?v=4)](https://github.com/janw-me "janw-me (5 commits)")[![gitlost](https://avatars.githubusercontent.com/u/481982?v=4)](https://github.com/gitlost "gitlost (5 commits)")[![mpeshev](https://avatars.githubusercontent.com/u/328189?v=4)](https://github.com/mpeshev "mpeshev (4 commits)")[![DrewAPicture](https://avatars.githubusercontent.com/u/995399?v=4)](https://github.com/DrewAPicture "DrewAPicture (4 commits)")[![francescolaffi](https://avatars.githubusercontent.com/u/357331?v=4)](https://github.com/francescolaffi "francescolaffi (4 commits)")

---

Tags

cacheclihacktoberfestwordpresswp-cliwp-cli-package

### Embed Badge

![Health badge](/badges/wp-cli-cache-command/health.svg)

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

###  Alternatives

[wp-cli/entity-command

Manage WordPress comments, menus, options, posts, sites, terms, and users.

1048.8M55](/packages/wp-cli-entity-command)[wp-cli/scaffold-command

Generates code for post types, taxonomies, blocks, plugins, child themes, etc.

1717.7M15](/packages/wp-cli-scaffold-command)[wp-cli/i18n-command

Provides internationalization tools for WordPress projects.

11610.4M52](/packages/wp-cli-i18n-command)[wp-cli/extension-command

Manages plugins and themes, including installs, activations, and updates.

919.0M53](/packages/wp-cli-extension-command)[wp-cli/db-command

Performs basic database operations using credentials stored in wp-config.php.

768.0M30](/packages/wp-cli-db-command)[wp-cli/server-command

Launches PHP's built-in web server for a specific WordPress installation.

687.2M5](/packages/wp-cli-server-command)

PHPackages © 2026

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