WP_Object_Cache::get()publicWP 2.0.0

Retrieves the cache contents, if it exists.

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.

Method of the class: WP_Object_Cache{}

No Hooks.

Return

Mixed|false. The cache contents on success, false on failure to retrieve contents.

Usage

$WP_Object_Cache = new WP_Object_Cache();
$WP_Object_Cache->get( $key, $group, $force, $found );
$key(int|string) (required)
The key under which the cache contents are stored.
$group(string)
Where the cache contents are grouped.
Default: 'default'
$force(true|false)
Unused. Whether to force an update of the local cache from the persistent cache.
Default: false
$found(true|false) (passed by reference — &)
Whether the key was found in the cache (passed by reference). Disambiguates a return of false, a storable value.
Default: null

Changelog

Since 2.0.0 Introduced.

WP_Object_Cache::get() code WP 6.4.3

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;
}