2017 © Pedro PelĂĄez
 

wp-cli-package cache-command

Manages object and transient caches.

image

wp-cli/cache-command

Manages object and transient caches.

  • Friday, April 20, 2018
  • by danielbachhuber
  • Repository
  • 3 Watchers
  • 10 Stars
  • 255,543 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 10 Forks
  • 3 Open issues
  • 9 Versions
  • 22 % Grown

The README.md

wp-cli/cache-command

Manages object and transient caches., (*1)

Testing, (*2)

Quick links: Using | Installing | Contributing | Support, (*3)

Using

This package implements the following commands:, (*4)

wp cache

Adds, removes, fetches, and flushes the WP Object Cache object., (*5)

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., (*6)

Read the codex article for more detail., (*7)

EXAMPLES, (*8)

# 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

Adds a value to the object cache., (*9)

wp cache add <key> <value> [<group>] [<expiration>]

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

OPTIONS, (*11)

<key>
    Cache key.

<value>
    Value to add to the key.

[<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
    ---

EXAMPLES, (*12)

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

wp cache decr

Decrements a value in the object cache., (*13)

wp cache decr <key> [<offset>] [<group>]

Errors if the value can't be decremented., (*14)

OPTIONS, (*15)

<key>
    Cache key.

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

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

EXAMPLES, (*16)

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

wp cache delete

Removes a value from the object cache., (*17)

wp cache delete <key> [<group>]

Errors if the value can't be deleted., (*18)

OPTIONS, (*19)

<key>
    Cache key.

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

EXAMPLES, (*20)

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

wp cache flush

Flushes the object cache., (*21)

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., (*22)

Errors if the object cache can't be flushed., (*23)

EXAMPLES, (*24)

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

wp cache flush-group

Removes all cache items in a group, if the object cache implementation supports it., (*25)

wp cache flush-group <group>

OPTIONS, (*26)

<group>
    Cache group key.

EXAMPLES, (*27)

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

wp cache get

Gets a value from the object cache., (*28)

wp cache get <key> [<group>]

Errors if the value doesn't exist., (*29)

OPTIONS, (*30)

<key>
    Cache key.

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

EXAMPLES, (*31)

# Get cache.
$ wp cache get my_key my_group
my_value

wp cache incr

Increments a value in the object cache., (*32)

wp cache incr <key> [<offset>] [<group>]

Errors if the value can't be incremented., (*33)

OPTIONS, (*34)

<key>
    Cache key.

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

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

EXAMPLES, (*35)

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

wp cache replace

Replaces a value in the object cache, if the value already exists., (*36)

wp cache replace <key> <value> [<group>] [<expiration>]

Errors if the value can't be replaced., (*37)

OPTIONS, (*38)

<key>
    Cache key.

<value>
    Value to replace.

[<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
    ---

EXAMPLES, (*39)

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

wp cache set

Sets a value to the object cache, regardless of whether it already exists., (*40)

wp cache set <key> <value> [<group>] [<expiration>]

Errors if the value can't be set., (*41)

OPTIONS, (*42)

<key>
    Cache key.

<value>
    Value to set on the key.

[<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
    ---

EXAMPLES, (*43)

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

wp cache supports

Determines whether the object cache implementation supports a particular feature., (*44)

wp cache supports <feature>

OPTIONS, (*45)

<feature>
    Name of the feature to check for.

EXAMPLES, (*46)

# 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

Attempts to determine which object cache is being used., (*47)

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., (*48)

EXAMPLES, (*49)

# Check cache type.
$ wp cache type
Default

wp transient

Adds, gets, and deletes entries in the WordPress Transient Cache., (*50)

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., (*51)

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., (*52)

EXAMPLES, (*53)

# 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.

wp transient delete

Deletes a transient value., (*54)

wp transient delete [<key>] [--network] [--all] [--expired]

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

OPTIONS, (*56)

[<key>]
    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, (*57)

# 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

Gets a transient value., (*58)

wp transient get <key> [--format=<format>] [--network]

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

OPTIONS, (*60)

<key>
    Key for the transient.

[--format=<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, (*61)

$ wp transient get sample_key
test data

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

wp transient set

Sets a transient value., (*62)

wp transient set <key> <value> [<expiration>] [--network]

<expiration> is the time until expiration, in seconds., (*63)

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

OPTIONS, (*65)

<key>
    Key for the transient.

<value>
    Value to be set for the transient.

[<expiration>]
    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, (*66)

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

wp transient type

Determines the type of transients implementation., (*67)

wp transient type 

Indicates whether the transients API is using an object cache or the database., (*68)

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

EXAMPLES, (*70)

$ wp transient type
Transients are saved to the database.

wp transient list

Lists transients and their values., (*71)

wp transient list [--search=<pattern>] [--exclude=<pattern>] [--network] [--unserialize] [--human-readable] [--fields=<fields>] [--format=<format>]

OPTIONS, (*72)

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

[--exclude=<pattern>]
    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=<fields>]
    Limit the output to specific object fields.

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

AVAILABLE FIELDS, (*73)

This field will be displayed by default for each matching option:, (*74)

  • name
  • value
  • expiration

EXAMPLES, (*75)

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

Installing

This package is included with WP-CLI itself, no additional installation necessary., (*76)

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

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

Contributing

We appreciate you taking the initiative to contribute to this project., (*78)

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., (*79)

For a more thorough introduction, check out WP-CLI's guide to contributing. This package follows those policy and guidelines., (*80)

Reporting a bug

Think you’ve found a bug? We’d love for you to help us get it fixed., (*81)

Before you create a new issue, you should search existing issues to see if there’s an existing resolution to it, or if it’s already been fixed in a newer version., (*82)

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. Include as much detail as you can, and clear steps to reproduce if possible. For more guidance, review our bug report documentation., (*83)

Creating a pull request

Want to contribute a new feature? Please first open a new issue to discuss whether the feature is a good fit for the project., (*84)

Once you've decided to commit the time to seeing your pull request through, please follow our guidelines for creating a pull request to make sure it's a pleasant experience. See "Setting up" for details specific to working on this package locally., (*85)

Support

GitHub issues aren't for general support questions, but there are other venues you can try: https://wp-cli.org/#support, (*86)

This README.md is generated dynamically from the project's codebase using wp scaffold package-readme (doc). To suggest changes, please submit a pull request against the corresponding part of the codebase., (*87)

The Versions

20/04 2018

dev-master

9999999-dev https://github.com/wp-cli/cache-command

Manages object and transient caches.

  Sources   Download

MIT

The Development Requires

20/04 2018

dev-refresh-scaffold-files

dev-refresh-scaffold-files https://github.com/wp-cli/cache-command

Manages object and transient caches.

  Sources   Download

MIT

The Development Requires

14/12 2017

v1.0.6

1.0.6.0 https://github.com/wp-cli/cache-command

Manages object and transient caches.

  Sources   Download

MIT

The Development Requires

20/11 2017

v1.0.5

1.0.5.0 https://github.com/wp-cli/cache-command

Manage object and transient caches.

  Sources   Download

MIT

The Development Requires

07/10 2017

v1.0.4

1.0.4.0 https://github.com/wp-cli/cache-command

Manage object and transient caches.

  Sources   Download

MIT

The Development Requires

30/09 2017

v1.0.3

1.0.3.0 https://github.com/wp-cli/cache-command

Manage object and transient caches.

  Sources   Download

MIT

The Development Requires

04/08 2017

v1.0.2

1.0.2.0 https://github.com/wp-cli/cache-command

Manage object and transient caches.

  Sources   Download

MIT

The Development Requires

30/05 2017

v1.0.1

1.0.1.0 https://github.com/wp-cli/cache-command

Manage object and transient caches.

  Sources   Download

MIT

The Development Requires

17/04 2017

v1.0.0

1.0.0.0 https://github.com/wp-cli/cache-command

Manage object and transient caches.

  Sources   Download

MIT

The Development Requires