WP_Object_Cache::get() WordPress Method

The WP_Object_Cache::get() method is used to retrieve data from the WordPress object cache. This is a global cache that is used to store data for use across all of WordPress. The object cache is used to improve performance by caching data so that it can be reused rather than queried from the database each time it is needed.

WP_Object_Cache::get( int|string $key, string $group = 'default', bool $force = false, bool $found = null ) #

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.


Top ↑

Parameters

$key

(int|string)(Required)The key under which the cache contents are stored.

$group

(string)(Optional) Where the cache contents are grouped.

Default value: 'default'

$force

(bool)(Optional) Unused. Whether to force an update of the local cache from the persistent cache.

Default value: false

$found

(bool)(Optional) Whether the key was found in the cache (passed by reference). Disambiguates a return of false, a storable value.

Default value: null


Top ↑

Return

(mixed|false) The cache contents on success, false on failure to retrieve contents.


Top ↑

Source

File: wp-includes/class-wp-object-cache.php

	public function get( $key, $group = 'default', $force = false, &$found = null ) {
		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;
	}


Top ↑

Changelog

Changelog
VersionDescription
2.0.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.