{"id":19639513,"url":"https://github.com/wp-cli/cache-command","last_synced_at":"2025-04-13T07:50:46.110Z","repository":{"id":45041307,"uuid":"88057295","full_name":"wp-cli/cache-command","owner":"wp-cli","description":"Manages object and transient caches.","archived":false,"fork":false,"pushed_at":"2025-03-09T15:39:35.000Z","size":8695,"stargazers_count":16,"open_issues_count":4,"forks_count":24,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-04-04T05:45:39.593Z","etag":null,"topics":["cache","cli","hacktoberfest","wordpress","wp-cli","wp-cli-package"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wp-cli.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-04-12T13:51:28.000Z","updated_at":"2025-03-29T19:38:33.000Z","dependencies_parsed_at":"2024-01-11T12:58:56.237Z","dependency_job_id":"b5c68c15-4384-46d0-b000-aafff385b505","html_url":"https://github.com/wp-cli/cache-command","commit_stats":{"total_commits":500,"total_committers":49,"mean_commits":"10.204081632653061","dds":0.73,"last_synced_commit":"80aa8e1546ac278be035731d41ec6d28213fb7db"},"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wp-cli%2Fcache-command","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wp-cli%2Fcache-command/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wp-cli%2Fcache-command/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wp-cli%2Fcache-command/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wp-cli","download_url":"https://codeload.github.com/wp-cli/cache-command/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248681494,"owners_count":21144700,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cache","cli","hacktoberfest","wordpress","wp-cli","wp-cli-package"],"created_at":"2024-11-11T13:01:35.907Z","updated_at":"2025-04-13T07:50:46.084Z","avatar_url":"https://github.com/wp-cli.png","language":"PHP","readme":"wp-cli/cache-command\n====================\n\nManages object and transient caches.\n\n[![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)\n\nQuick links: [Using](#using) | [Installing](#installing) | [Contributing](#contributing) | [Support](#support)\n\n## Using\n\nThis package implements the following commands:\n\n### wp cache\n\nAdds, removes, fetches, and flushes the WP Object Cache object.\n\n~~~\nwp cache\n~~~\n\nBy default, the WP Object Cache exists in PHP memory for the length of the\nrequest (and is emptied at the end). Use a persistent object cache drop-in\nto persist the object cache between requests.\n\n[Read the codex article](https://codex.wordpress.org/Class_Reference/WP_Object_Cache)\nfor more detail.\n\n**EXAMPLES**\n\n    # Set cache.\n    $ wp cache set my_key my_value my_group 300\n    Success: Set object 'my_key' in group 'my_group'.\n\n    # Get cache.\n    $ wp cache get my_key my_group\n    my_value\n\n\n\n### wp cache add\n\nAdds a value to the object cache.\n\n~~~\nwp cache add \u003ckey\u003e \u003cvalue\u003e [\u003cgroup\u003e] [\u003cexpiration\u003e]\n~~~\n\nErrors if a value already exists for the key, which means the value can't\nbe added.\n\n**OPTIONS**\n\n\t\u003ckey\u003e\n\t\tCache key.\n\n\t\u003cvalue\u003e\n\t\tValue to add to the key.\n\n\t[\u003cgroup\u003e]\n\t\tMethod for grouping data within the cache which allows the same key to be used across groups.\n\t\t---\n\t\tdefault: default\n\t\t---\n\n\t[\u003cexpiration\u003e]\n\t\tDefine how long to keep the value, in seconds. `0` means as long as possible.\n\t\t---\n\t\tdefault: 0\n\t\t---\n\n**EXAMPLES**\n\n    # Add cache.\n    $ wp cache add my_key my_group my_value 300\n    Success: Added object 'my_key' in group 'my_value'.\n\n\n\n### wp cache decr\n\nDecrements a value in the object cache.\n\n~~~\nwp cache decr \u003ckey\u003e [\u003coffset\u003e] [\u003cgroup\u003e]\n~~~\n\nErrors if the value can't be decremented.\n\n**OPTIONS**\n\n\t\u003ckey\u003e\n\t\tCache key.\n\n\t[\u003coffset\u003e]\n\t\tThe amount by which to decrement the item's value.\n\t\t---\n\t\tdefault: 1\n\t\t---\n\n\t[\u003cgroup\u003e]\n\t\tMethod for grouping data within the cache which allows the same key to be used across groups.\n\t\t---\n\t\tdefault: default\n\t\t---\n\n**EXAMPLES**\n\n    # Decrease cache value.\n    $ wp cache decr my_key 2 my_group\n    48\n\n\n\n### wp cache delete\n\nRemoves a value from the object cache.\n\n~~~\nwp cache delete \u003ckey\u003e [\u003cgroup\u003e]\n~~~\n\nErrors if the value can't be deleted.\n\n**OPTIONS**\n\n\t\u003ckey\u003e\n\t\tCache key.\n\n\t[\u003cgroup\u003e]\n\t\tMethod for grouping data within the cache which allows the same key to be used across groups.\n\t\t---\n\t\tdefault: default\n\t\t---\n\n**EXAMPLES**\n\n    # Delete cache.\n    $ wp cache delete my_key my_group\n    Success: Object deleted.\n\n\n\n### wp cache flush\n\nFlushes the object cache.\n\n~~~\nwp cache flush \n~~~\n\nFor WordPress multisite instances using a persistent object cache,\nflushing the object cache will typically flush the cache for all sites.\nBeware of the performance impact when flushing the object cache in\nproduction.\n\nErrors if the object cache can't be flushed.\n\n**EXAMPLES**\n\n    # Flush cache.\n    $ wp cache flush\n    Success: The cache was flushed.\n\n\n\n### wp cache flush-group\n\nRemoves all cache items in a group, if the object cache implementation supports it.\n\n~~~\nwp cache flush-group \u003cgroup\u003e\n~~~\n\n**OPTIONS**\n\n\t\u003cgroup\u003e\n\t\tCache group key.\n\n**EXAMPLES**\n\n    # Clear cache group.\n    $ wp cache flush-group my_group\n    Success: Cache group 'my_group' was flushed.\n\n\n\n### wp cache get\n\nGets a value from the object cache.\n\n~~~\nwp cache get \u003ckey\u003e [\u003cgroup\u003e]\n~~~\n\nErrors if the value doesn't exist.\n\n**OPTIONS**\n\n\t\u003ckey\u003e\n\t\tCache key.\n\n\t[\u003cgroup\u003e]\n\t\tMethod for grouping data within the cache which allows the same key to be used across groups.\n\t\t---\n\t\tdefault: default\n\t\t---\n\n**EXAMPLES**\n\n    # Get cache.\n    $ wp cache get my_key my_group\n    my_value\n\n\n\n### wp cache incr\n\nIncrements a value in the object cache.\n\n~~~\nwp cache incr \u003ckey\u003e [\u003coffset\u003e] [\u003cgroup\u003e]\n~~~\n\nErrors if the value can't be incremented.\n\n**OPTIONS**\n\n\t\u003ckey\u003e\n\t\tCache key.\n\n\t[\u003coffset\u003e]\n\t\tThe amount by which to increment the item's value.\n\t\t---\n\t\tdefault: 1\n\t\t---\n\n\t[\u003cgroup\u003e]\n\t\tMethod for grouping data within the cache which allows the same key to be used across groups.\n\t\t---\n\t\tdefault: default\n\t\t---\n\n**EXAMPLES**\n\n    # Increase cache value.\n    $ wp cache incr my_key 2 my_group\n    50\n\n\n\n### wp cache replace\n\nReplaces a value in the object cache, if the value already exists.\n\n~~~\nwp cache replace \u003ckey\u003e \u003cvalue\u003e [\u003cgroup\u003e] [\u003cexpiration\u003e]\n~~~\n\nErrors if the value can't be replaced.\n\n**OPTIONS**\n\n\t\u003ckey\u003e\n\t\tCache key.\n\n\t\u003cvalue\u003e\n\t\tValue to replace.\n\n\t[\u003cgroup\u003e]\n\t\tMethod for grouping data within the cache which allows the same key to be used across groups.\n\t\t---\n\t\tdefault: default\n\t\t---\n\n\t[\u003cexpiration\u003e]\n\t\tDefine how long to keep the value, in seconds. `0` means as long as possible.\n\t\t---\n\t\tdefault: 0\n\t\t---\n\n**EXAMPLES**\n\n    # Replace cache.\n    $ wp cache replace my_key new_value my_group\n    Success: Replaced object 'my_key' in group 'my_group'.\n\n\n\n### wp cache set\n\nSets a value to the object cache, regardless of whether it already exists.\n\n~~~\nwp cache set \u003ckey\u003e \u003cvalue\u003e [\u003cgroup\u003e] [\u003cexpiration\u003e]\n~~~\n\nErrors if the value can't be set.\n\n**OPTIONS**\n\n\t\u003ckey\u003e\n\t\tCache key.\n\n\t\u003cvalue\u003e\n\t\tValue to set on the key.\n\n\t[\u003cgroup\u003e]\n\t\tMethod for grouping data within the cache which allows the same key to be used across groups.\n\t\t---\n\t\tdefault: default\n\t\t---\n\n\t[\u003cexpiration\u003e]\n\t\tDefine how long to keep the value, in seconds. `0` means as long as possible.\n\t\t---\n\t\tdefault: 0\n\t\t---\n\n**EXAMPLES**\n\n    # Set cache.\n    $ wp cache set my_key my_value my_group 300\n    Success: Set object 'my_key' in group 'my_group'.\n\n\n\n### wp cache supports\n\nDetermines whether the object cache implementation supports a particular feature.\n\n~~~\nwp cache supports \u003cfeature\u003e\n~~~\n\n**OPTIONS**\n\n\t\u003cfeature\u003e\n\t\tName of the feature to check for.\n\n**EXAMPLES**\n\n    # Check whether is add_multiple supported.\n    $ wp cache supports add_multiple\n    $ echo $?\n    0\n\n    # Bash script for checking whether for support like this:\n    if ! wp cache supports non_existing; then\n        echo 'non_existing is not supported'\n    fi\n\n\n\n### wp cache type\n\nAttempts to determine which object cache is being used.\n\n~~~\nwp cache type \n~~~\n\nNote that the guesses made by this function are based on the\nWP_Object_Cache classes that define the 3rd party object cache extension.\nChanges to those classes could render problems with this function's\nability to determine which object cache is being used.\n\n**EXAMPLES**\n\n    # Check cache type.\n    $ wp cache type\n    Default\n\n\n\n### wp transient\n\nAdds, gets, and deletes entries in the WordPress Transient Cache.\n\n~~~\nwp transient\n~~~\n\nBy default, the transient cache uses the WordPress database to persist values\nbetween requests. On a single site installation, values are stored in the\n`wp_options` table. On a multisite installation, values are stored in the\n`wp_options` or the `wp_sitemeta` table, depending on use of the `--network`\nflag.\n\nWhen a persistent object cache drop-in is installed (e.g. Redis or Memcached),\nthe transient cache skips the database and simply wraps the WP Object Cache.\n\n**EXAMPLES**\n\n    # Set transient.\n    $ wp transient set sample_key \"test data\" 3600\n    Success: Transient added.\n\n    # Get transient.\n    $ wp transient get sample_key\n    test data\n\n    # Delete transient.\n    $ wp transient delete sample_key\n    Success: Transient deleted.\n\n    # Delete expired transients.\n    $ wp transient delete --expired\n    Success: 12 expired transients deleted from the database.\n\n    # Delete all transients.\n    $ wp transient delete --all\n    Success: 14 transients deleted from the database.\n\n\n\n### wp transient delete\n\nDeletes a transient value.\n\n~~~\nwp transient delete [\u003ckey\u003e] [--network] [--all] [--expired]\n~~~\n\nFor a more complete explanation of the transient cache, including the\nnetwork|site cache, please see docs for `wp transient`.\n\n**OPTIONS**\n\n\t[\u003ckey\u003e]\n\t\tKey for the transient.\n\n\t[--network]\n\t\tDelete the value of a network|site transient. On single site, this is\n\t\tis a specially-named cache key. On multisite, this is a global cache\n\t\t(instead of local to the site).\n\n\t[--all]\n\t\tDelete all transients.\n\n\t[--expired]\n\t\tDelete all expired transients.\n\n**EXAMPLES**\n\n    # Delete transient.\n    $ wp transient delete sample_key\n    Success: Transient deleted.\n\n    # Delete expired transients.\n    $ wp transient delete --expired\n    Success: 12 expired transients deleted from the database.\n\n    # Delete expired site transients.\n    $ wp transient delete --expired --network\n    Success: 1 expired transient deleted from the database.\n\n    # Delete all transients.\n    $ wp transient delete --all\n    Success: 14 transients deleted from the database.\n\n    # Delete all site transients.\n    $ wp transient delete --all --network\n    Success: 2 transients deleted from the database.\n\n    # Delete all transients in a multisite.\n    $ wp transient delete --all --network \u0026\u0026 wp site list --field=url | xargs -n1 -I % wp --url=% transient delete --all\n\n\n\n### wp transient get\n\nGets a transient value.\n\n~~~\nwp transient get \u003ckey\u003e [--format=\u003cformat\u003e] [--network]\n~~~\n\nFor a more complete explanation of the transient cache, including the\nnetwork|site cache, please see docs for `wp transient`.\n\n**OPTIONS**\n\n\t\u003ckey\u003e\n\t\tKey for the transient.\n\n\t[--format=\u003cformat\u003e]\n\t\tRender output in a particular format.\n\t\t---\n\t\tdefault: table\n\t\toptions:\n\t\t  - table\n\t\t  - csv\n\t\t  - json\n\t\t  - yaml\n\t\t---\n\n\t[--network]\n\t\tGet the value of a network|site transient. On single site, this is\n\t\tis a specially-named cache key. On multisite, this is a global cache\n\t\t(instead of local to the site).\n\n**EXAMPLES**\n\n    $ wp transient get sample_key\n    test data\n\n    $ wp transient get random_key\n    Warning: Transient with key \"random_key\" is not set.\n\n\n\n### wp transient set\n\nSets a transient value.\n\n~~~\nwp transient set \u003ckey\u003e \u003cvalue\u003e [\u003cexpiration\u003e] [--network]\n~~~\n\n`\u003cexpiration\u003e` is the time until expiration, in seconds.\n\nFor a more complete explanation of the transient cache, including the\nnetwork|site cache, please see docs for `wp transient`.\n\n**OPTIONS**\n\n\t\u003ckey\u003e\n\t\tKey for the transient.\n\n\t\u003cvalue\u003e\n\t\tValue to be set for the transient.\n\n\t[\u003cexpiration\u003e]\n\t\tTime until expiration, in seconds.\n\n\t[--network]\n\t\tSet the value of a network|site transient. On single site, this is\n\t\tis a specially-named cache key. On multisite, this is a global cache\n\t\t(instead of local to the site).\n\n**EXAMPLES**\n\n    $ wp transient set sample_key \"test data\" 3600\n    Success: Transient added.\n\n\n\n### wp transient type\n\nDetermines the type of transients implementation.\n\n~~~\nwp transient type \n~~~\n\nIndicates whether the transients API is using an object cache or the\ndatabase.\n\nFor a more complete explanation of the transient cache, including the\nnetwork|site cache, please see docs for `wp transient`.\n\n**EXAMPLES**\n\n    $ wp transient type\n    Transients are saved to the database.\n\n\n\n### wp transient list\n\nLists transients and their values.\n\n~~~\nwp transient list [--search=\u003cpattern\u003e] [--exclude=\u003cpattern\u003e] [--network] [--unserialize] [--human-readable] [--fields=\u003cfields\u003e] [--format=\u003cformat\u003e]\n~~~\n\n**OPTIONS**\n\n\t[--search=\u003cpattern\u003e]\n\t\tUse wildcards ( * and ? ) to match transient name.\n\n\t[--exclude=\u003cpattern\u003e]\n\t\tPattern to exclude. Use wildcards ( * and ? ) to match transient name.\n\n\t[--network]\n\t\tGet the values of network|site transients. On single site, this is\n\t\ta specially-named cache key. On multisite, this is a global cache\n\t\t(instead of local to the site).\n\n\t[--unserialize]\n\t\tUnserialize transient values in output.\n\n\t[--human-readable]\n\t\tHuman-readable output for expirations.\n\n\t[--fields=\u003cfields\u003e]\n\t\tLimit the output to specific object fields.\n\n\t[--format=\u003cformat\u003e]\n\t\tThe serialization format for the value.\n\t\t---\n\t\tdefault: table\n\t\toptions:\n\t\t  - table\n\t\t  - json\n\t\t  - csv\n\t\t  - count\n\t\t  - yaml\n\t\t---\n\n**AVAILABLE FIELDS**\n\nThis field will be displayed by default for each matching option:\n\n* name\n* value\n* expiration\n\n**EXAMPLES**\n\n    # List all transients\n    $ wp transient list\n     +------+-------+---------------+\n     | name | value | expiration    |\n     +------+-------+---------------+\n     | foo  | bar   | 39 mins       |\n     | foo2 | bar2  | no expiration |\n     | foo3 | bar2  | expired       |\n     | foo4 | bar4  | 4 hours       |\n     +------+-------+---------------+\n\n## Installing\n\nThis package is included with WP-CLI itself, no additional installation necessary.\n\nTo install the latest version of this package over what's included in WP-CLI, run:\n\n    wp package install git@github.com:wp-cli/cache-command.git\n\n## Contributing\n\nWe appreciate you taking the initiative to contribute to this project.\n\nContributing 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.\n\nFor 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.\n\n### Reporting a bug\n\nThink you’ve found a bug? We’d love for you to help us get it fixed.\n\nBefore 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.\n\nOnce 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/).\n\n### Creating a pull request\n\nWant 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.\n\nOnce 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.\n\n## Support\n\nGitHub issues aren't for general support questions, but there are other venues you can try: https://wp-cli.org/#support\n\n\n*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.*\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwp-cli%2Fcache-command","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwp-cli%2Fcache-command","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwp-cli%2Fcache-command/lists"}