WP_Object_Cache::get

Advertisement

Summery Summery

Retrieves the cache contents, if it exists.

Syntax Syntax

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

Description 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 Parameters

$key

(Required) What the contents in the cache are called.

$group

(Optional) Where the cache contents are grouped. Default 'default'.

Default value: 'default'

$force

(Optional) Unused. Whether to force a refetch rather than relying on the local cache.

Default value: false

$found

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

Default value: null

Return Return

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

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

Advertisement

Changelog Changelog

Changelog
Version Description
2.0.0 Introduced.

Advertisement

Leave a Reply