PHP 클래스 WP_Object_Cache, wp-redis

The WordPress Object Cache is used to save on trips to the database. The Object Cache stores all of the cache data to memory and makes the cache contents available by using a key, which is used to name and later retrieve the cache contents. The Object Cache can be replaced by other caching mechanisms by placing files in the wp-content folder which is looked at in wp-settings. If that file exists, then this file will not be included.
파일 보기 프로젝트 열기: pantheon-systems/wp-redis 1 사용 예제들

공개 프로퍼티들

프로퍼티 타입 설명
$blog_prefix integer The blog prefix to prepend to keys in non-global groups.
$cache array Holds the cached objects
$cache_hits integer The amount of times the cache data was already stored in the cache.
$cache_misses integer Amount of times the cache did not have the request in cache
$do_redis_failback_flush boolean Whether or not the object cache thinks Redis needs a flush
$global_groups array List of global groups
$is_redis_connected boolean Whether or not Redis is connected
$last_triggered_error The last triggered error
$non_persistent_groups array List of non-persistent groups
$redis_calls integer The amount of times a request was made to Redis
$redis_hash_groups array List of groups which use Redis hashes.

공개 메소드들

메소드 설명
__construct ( ) : null | WP_Object_Cache Sets up object properties; PHP 5 style constructor
__destruct ( ) : boolean Will save the object cache before object is completely destroyed.
add ( integer | string $key, mixed $data, string $group = 'default', integer $expire ) : boolean Adds data to the cache if it doesn't already exist.
add_global_groups ( array $groups ) Sets the list of global groups.
add_non_persistent_groups ( array $groups ) Sets the list of non-persistent groups.
add_redis_hash_groups ( array $groups ) Sets the list of groups that use Redis hashes.
decr ( integer | string $key, integer $offset = 1, string $group = 'default' ) : false | integer Decrement numeric cache item's value
delete ( integer | string $key, string $group = 'default', boolean $force = false ) : boolean Remove the contents of the cache key in the group
delete_group ( string $group ) : boolean Remove the contents of all cache keys in the group.
flush ( boolean $redis = true ) : boolean Clears the object cache of all data.
get ( integer | string $key, string $group = 'default', string $force = false, boolean &$found = null ) : boolean | mixed Retrieves the cache contents, if it exists
incr ( integer | string $key, integer $offset = 1, string $group = 'default' ) : false | integer Increment numeric cache item's value
replace ( integer | string $key, mixed $data, string $group = 'default', integer $expire ) : boolean Replace the contents in the cache, if contents already exist
reset ( ) Reset keys
set ( integer | string $key, mixed $data, string $group = 'default', integer $expire ) : boolean Sets the data contents into the cache
stats ( ) Echoes the stats of the caching.
switch_to_blog ( integer $blog_id ) Switch the interal blog id.
wp_action_admin_notices_warn_missing_redis ( ) Admin UI to let the end user know something about the Redis connection isn't working.

보호된 메소드들

메소드 설명
_call_redis ( string $method ) : mixed Wrapper method for calls to Redis, which fails gracefully when Redis is unavailable
_connect_redis ( ) Wrapper method for connecting to Redis, which lets us retry the connection
_exists ( $key, $group ) Utility function to determine whether a key exists in the cache.
_get_internal ( string $key, string $group ) : mixed Get a value from the internal object cache
_isset_internal ( string $key, string $group ) : boolean Check whether there's a value in the internal object cache.
_key ( string $key = '', string $group = 'default' ) : string Utility function to generate the redis key for a given key and group.
_set_internal ( string $key, string $group, mixed $value ) Set a value to the internal object cache
_should_persist ( string $group ) : boolean Does this group use persistent storage?
_should_use_redis_hashes ( string $group ) : boolean Should this group use Redis hashes?
_unset_internal ( string $key, string $group ) Unset a value from the internal object cache

비공개 메소드들

메소드 설명
is_redis_failback_flush_enabled ( ) : boolean Whether or not wakeup flush is enabled

메소드 상세

__construct() 공개 메소드

Sets up object properties; PHP 5 style constructor
public __construct ( ) : null | WP_Object_Cache
리턴 null | WP_Object_Cache If cache is disabled, returns null.

__destruct() 공개 메소드

Called upon object destruction, which should be when PHP ends.
public __destruct ( ) : boolean
리턴 boolean True value. Won't be used by PHP

_call_redis() 보호된 메소드

Wrapper method for calls to Redis, which fails gracefully when Redis is unavailable
protected _call_redis ( string $method ) : mixed
$method string
리턴 mixed

_connect_redis() 보호된 메소드

Wrapper method for connecting to Redis, which lets us retry the connection
protected _connect_redis ( )

_exists() 보호된 메소드

Utility function to determine whether a key exists in the cache.
protected _exists ( $key, $group )

_get_internal() 보호된 메소드

Get a value from the internal object cache
protected _get_internal ( string $key, string $group ) : mixed
$key string
$group string
리턴 mixed

_isset_internal() 보호된 메소드

Check whether there's a value in the internal object cache.
protected _isset_internal ( string $key, string $group ) : boolean
$key string
$group string
리턴 boolean

_key() 보호된 메소드

Utility function to generate the redis key for a given key and group.
protected _key ( string $key = '', string $group = 'default' ) : string
$key string The cache key.
$group string The cache group.
리턴 string A properly prefixed redis cache key.

_set_internal() 보호된 메소드

Set a value to the internal object cache
protected _set_internal ( string $key, string $group, mixed $value )
$key string
$group string
$value mixed

_should_persist() 보호된 메소드

Does this group use persistent storage?
protected _should_persist ( string $group ) : boolean
$group string Cache group.
리턴 boolean true if the group is persistent, false if not.

_should_use_redis_hashes() 보호된 메소드

Should this group use Redis hashes?
protected _should_use_redis_hashes ( string $group ) : boolean
$group string Cache group.
리턴 boolean True if the group should use Redis hashes, false if not.

_unset_internal() 보호된 메소드

Unset a value from the internal object cache
protected _unset_internal ( string $key, string $group )
$key string
$group string

add() 공개 메소드

Adds data to the cache if it doesn't already exist.
public add ( integer | string $key, mixed $data, string $group = 'default', integer $expire ) : boolean
$key integer | string What to call the contents in the cache
$data mixed The contents to store in the cache
$group string Where to group the cache contents
$expire integer When to expire the cache contents
리턴 boolean False if cache key and group already exist, true on success

add_global_groups() 공개 메소드

Sets the list of global groups.
public add_global_groups ( array $groups )
$groups array List of groups that are global.

add_non_persistent_groups() 공개 메소드

Sets the list of non-persistent groups.
public add_non_persistent_groups ( array $groups )
$groups array List of groups that are non-persistent.

add_redis_hash_groups() 공개 메소드

Sets the list of groups that use Redis hashes.
public add_redis_hash_groups ( array $groups )
$groups array List of groups that use Redis hashes.

decr() 공개 메소드

Decrement numeric cache item's value
public decr ( integer | string $key, integer $offset = 1, string $group = 'default' ) : false | integer
$key integer | string The cache key to increment
$offset integer The amount by which to decrement the item's value. Default is 1.
$group string The group the key is in.
리턴 false | integer False on failure, the item's new value on success.

delete() 공개 메소드

If the cache key does not exist in the group and $force parameter is set to false, then nothing will happen. The $force parameter is set to false by default.
public delete ( integer | string $key, string $group = 'default', boolean $force = false ) : boolean
$key integer | string What the contents in the cache are called
$group string Where the cache contents are grouped
$force boolean Optional. Whether to force the unsetting of the cache key in the group
리턴 boolean False if the contents weren't deleted and true on success

delete_group() 공개 메소드

Remove the contents of all cache keys in the group.
public delete_group ( string $group ) : boolean
$group string Where the cache contents are grouped.
리턴 boolean True on success, false on failure.

flush() 공개 메소드

By default, this will flush the session cache as well as Redis, but we can leave the redis cache intact if we want. This is helpful when, for instance, you're running a batch process and want to clear the session store to reduce the memory footprint, but you don't want to have to re-fetch all the values from the database.
public flush ( boolean $redis = true ) : boolean
$redis boolean Should we flush redis as well as the session cache?
리턴 boolean Always returns true

get() 공개 메소드

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.
public get ( integer | string $key, string $group = 'default', string $force = false, boolean &$found = null ) : boolean | mixed
$key integer | string What the contents in the cache are called
$group string Where the cache contents are grouped
$force string Whether to force a refetch rather than relying on the local cache (default is false)
$found boolean Optional. Whether the key was found in the cache. Disambiguates a return of false, a storable value. Passed by reference. Default null.
리턴 boolean | mixed False on failure to retrieve contents or the cache contents on success

incr() 공개 메소드

Increment numeric cache item's value
public incr ( integer | string $key, integer $offset = 1, string $group = 'default' ) : false | integer
$key integer | string The cache key to increment
$offset integer The amount by which to increment the item's value. Default is 1.
$group string The group the key is in.
리턴 false | integer False on failure, the item's new value on success.

replace() 공개 메소드

Replace the contents in the cache, if contents already exist
또한 보기: WP_Object_Cache::set()
public replace ( integer | string $key, mixed $data, string $group = 'default', integer $expire ) : boolean
$key integer | string What to call the contents in the cache
$data mixed The contents to store in the cache
$group string Where to group the cache contents
$expire integer When to expire the cache contents
리턴 boolean False if not exists, true if contents were replaced

reset() 공개 메소드

Reset keys
사용 중단: 3.5.0
public reset ( )

set() 공개 메소드

The cache contents is grouped by the $group parameter followed by the $key. This allows for duplicate ids in unique groups. Therefore, naming of the group should be used with care and should follow normal function naming guidelines outside of core WordPress usage. The $expire parameter is not used, because the cache will automatically expire for each time a page is accessed and PHP finishes. The method is more for cache plugins which use files.
public set ( integer | string $key, mixed $data, string $group = 'default', integer $expire ) : boolean
$key integer | string What to call the contents in the cache
$data mixed The contents to store in the cache
$group string Where to group the cache contents
$expire integer TTL for the data, in seconds
리턴 boolean Always returns true

stats() 공개 메소드

Gives the cache hits, and cache misses. Also prints every cached group, key and the data.
public stats ( )

switch_to_blog() 공개 메소드

This changes the blog id used to create keys in blog specific groups.
public switch_to_blog ( integer $blog_id )
$blog_id integer Blog ID

wp_action_admin_notices_warn_missing_redis() 공개 메소드

Admin UI to let the end user know something about the Redis connection isn't working.

프로퍼티 상세

$blog_prefix 공개적으로 프로퍼티

The blog prefix to prepend to keys in non-global groups.
public int $blog_prefix
리턴 integer

$cache 공개적으로 프로퍼티

Holds the cached objects
public array $cache
리턴 array

$cache_hits 공개적으로 프로퍼티

The amount of times the cache data was already stored in the cache.
public int $cache_hits
리턴 integer

$cache_misses 공개적으로 프로퍼티

Amount of times the cache did not have the request in cache
public int $cache_misses
리턴 integer

$do_redis_failback_flush 공개적으로 프로퍼티

Whether or not the object cache thinks Redis needs a flush
public bool $do_redis_failback_flush
리턴 boolean

$global_groups 공개적으로 프로퍼티

List of global groups
public array $global_groups
리턴 array

$is_redis_connected 공개적으로 프로퍼티

Whether or not Redis is connected
public bool $is_redis_connected
리턴 boolean

$last_triggered_error 공개적으로 프로퍼티

The last triggered error
public $last_triggered_error

$non_persistent_groups 공개적으로 프로퍼티

List of non-persistent groups
public array $non_persistent_groups
리턴 array

$redis_calls 공개적으로 프로퍼티

The amount of times a request was made to Redis
public int $redis_calls
리턴 integer

$redis_hash_groups 공개적으로 프로퍼티

List of groups which use Redis hashes.
public array $redis_hash_groups
리턴 array