On this page
WP_Object_Cache::get( int|string $key, string $group = 'default', bool $force = false, bool $found = null ): mixed|false
Retrieves the cache contents, if it exists.
Description
The contents will be first attempted to be retrieved by searching by the key in the cache group. If the cache is hit (success) then the contents are returned.
On failure, the number of cache misses will be incremented.
Parameters
$keyint|string Required-
The key under which the cache contents are stored.
$groupstring Optional-
Where the cache contents are grouped. Default
'default'.Default:
'default' $forcebool Optional-
Unused. Whether to force an update of the local cache from the persistent cache.
Default:
false $foundbool Optional-
Whether the key was found in the cache (passed by reference).
Disambiguates a return of false, a storable value.Default:
null
Return
mixed|false The cache contents on success, false on failure to retrieve contents.
Source
File: wp-includes/class-wp-object-cache.php. View all references
public function get( $key, $group = 'default', $force = false, &$found = null ) {
if ( ! $this->is_valid_key( $key ) ) {
return false;
}
if ( empty( $group ) ) {
$group = 'default';
}
if ( $this->multisite && ! isset( $this->global_groups[ $group ] ) ) {
$key = $this->blog_prefix . $key;
}
if ( $this->_exists( $key, $group ) ) {
$found = true;
$this->cache_hits += 1;
if ( is_object( $this->cache[ $group ][ $key ] ) ) {
return clone $this->cache[ $group ][ $key ];
} else {
return $this->cache[ $group ][ $key ];
}
}
$found = false;
$this->cache_misses += 1;
return false;
}
Related
Uses
| Uses | Description |
|---|---|
| WP_Object_Cache::is_valid_key() wp-includes/class-wp-object-cache.php | Serves as a utility function to determine whether a key is valid. |
| WP_Object_Cache::_exists() wp-includes/class-wp-object-cache.php | Serves as a utility function to determine whether a key exists in the cache. |
Used By
| Used By | Description |
|---|---|
| WP_Object_Cache::get_multiple() wp-includes/class-wp-object-cache.php | Retrieves multiple values from the cache in one call. |
| wp_cache_get() wp-includes/cache.php | Retrieves the cache contents from the cache by key and group. |
Changelog
| Version | Description |
|---|---|
| 2.0.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_object_cache/get