wp/wp-includes/class-wp-object-cache.php
author ymh <ymh.work@gmail.com>
Tue, 27 Sep 2022 16:37:53 +0200
changeset 19 3d72ae0968f4
parent 18 be944660c56a
child 21 48c4eec2b7e6
permissions -rw-r--r--
upgrade wordpress to 6.0.2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<?php
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
 * Object Cache API: WP_Object_Cache class
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
 * @package WordPress
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
 * @subpackage Cache
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
 * @since 5.4.0
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
 * Core class that implements an object cache.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
 * The WordPress Object Cache is used to save on trips to the database. The
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
 * Object Cache stores all of the cache data to memory and makes the cache
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
 * contents available by using a key, which is used to name and later retrieve
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
 * the cache contents.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
 * The Object Cache can be replaced by other caching mechanisms by placing files
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
 * in the wp-content folder which is looked at in wp-settings. If that file
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
 * exists, then this file will not be included.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
 * @since 2.0.0
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
class WP_Object_Cache {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
	/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
	 * Holds the cached objects.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
	 * @since 2.0.0
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
	 * @var array
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
	 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
	private $cache = array();
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
	/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
	 * The amount of times the cache data was already stored in the cache.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
	 * @since 2.5.0
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
	 * @var int
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
	 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
	public $cache_hits = 0;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
	/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
	 * Amount of times the cache did not have the request in cache.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
	 * @since 2.0.0
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
	 * @var int
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
	 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
	public $cache_misses = 0;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
	/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
	 * List of global cache groups.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
	 * @since 3.0.0
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
	 * @var array
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
	 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
	protected $global_groups = array();
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
	/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
	 * The blog prefix to prepend to keys in non-global groups.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
	 * @since 3.5.0
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
	 * @var string
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
	 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
	private $blog_prefix;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
	/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
	 * Holds the value of is_multisite().
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
	 * @since 3.5.0
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
	 * @var bool
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
	 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
	private $multisite;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
	/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
	 * Sets up object properties; PHP 5 style constructor.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
	 * @since 2.0.8
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
	 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
	public function __construct() {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
		$this->multisite   = is_multisite();
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
		$this->blog_prefix = $this->multisite ? get_current_blog_id() . ':' : '';
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
	}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    84
	/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
	 * Makes private properties readable for backward compatibility.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
	 * @since 4.0.0
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
	 * @param string $name Property to get.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
	 * @return mixed Property.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
	 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
	public function __get( $name ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    93
		return $this->$name;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    94
	}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    95
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    96
	/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    97
	 * Makes private properties settable for backward compatibility.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    98
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
    99
	 * @since 4.0.0
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
	 * @param string $name  Property to set.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   102
	 * @param mixed  $value Property value.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
	 * @return mixed Newly-set property.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   104
	 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
	public function __set( $name, $value ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   106
		return $this->$name = $value;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
	}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
	/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   110
	 * Makes private properties checkable for backward compatibility.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   111
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   112
	 * @since 4.0.0
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   114
	 * @param string $name Property to check if set.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   115
	 * @return bool Whether the property is set.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   116
	 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
	public function __isset( $name ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
		return isset( $this->$name );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   119
	}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   120
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   121
	/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   122
	 * Makes private properties un-settable for backward compatibility.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   123
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   124
	 * @since 4.0.0
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   125
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
	 * @param string $name Property to unset.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   127
	 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   128
	public function __unset( $name ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   129
		unset( $this->$name );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   130
	}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   132
	/**
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   133
	 * Serves as a utility function to determine whether a key exists in the cache.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   134
	 *
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   135
	 * @since 3.4.0
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   136
	 *
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   137
	 * @param int|string $key   Cache key to check for existence.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   138
	 * @param string     $group Cache group for the key existence check.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   139
	 * @return bool Whether the key exists in the cache for the given group.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   140
	 */
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   141
	protected function _exists( $key, $group ) {
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   142
		return isset( $this->cache[ $group ] ) && ( isset( $this->cache[ $group ][ $key ] ) || array_key_exists( $key, $this->cache[ $group ] ) );
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   143
	}
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   144
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   145
	/**
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   146
	 * Adds data to the cache if it doesn't already exist.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   147
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   148
	 * @since 2.0.0
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   149
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   150
	 * @uses WP_Object_Cache::_exists() Checks to see if the cache already has data.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   151
	 * @uses WP_Object_Cache::set()     Sets the data after the checking the cache
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   152
	 *                                  contents existence.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   153
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   154
	 * @param int|string $key    What to call the contents in the cache.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   155
	 * @param mixed      $data   The contents to store in the cache.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   156
	 * @param string     $group  Optional. Where to group the cache contents. Default 'default'.
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   157
	 * @param int        $expire Optional. When to expire the cache contents, in seconds.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   158
	 *                           Default 0 (no expiration).
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   159
	 * @return bool True on success, false if cache key and group already exist.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   160
	 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   161
	public function add( $key, $data, $group = 'default', $expire = 0 ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   162
		if ( wp_suspend_cache_addition() ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
			return false;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   164
		}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   165
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   166
		if ( empty( $group ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   167
			$group = 'default';
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   168
		}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   169
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   170
		$id = $key;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   171
		if ( $this->multisite && ! isset( $this->global_groups[ $group ] ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   172
			$id = $this->blog_prefix . $key;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   173
		}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   174
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   175
		if ( $this->_exists( $id, $group ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   176
			return false;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   177
		}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   178
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   179
		return $this->set( $key, $data, $group, (int) $expire );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   180
	}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   181
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   182
	/**
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   183
	 * Adds multiple values to the cache in one call.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   184
	 *
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   185
	 * @since 6.0.0
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   186
	 *
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   187
	 * @param array  $data   Array of keys and values to be added.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   188
	 * @param string $group  Optional. Where the cache contents are grouped. Default empty.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   189
	 * @param int    $expire Optional. When to expire the cache contents, in seconds.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   190
	 *                       Default 0 (no expiration).
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   191
	 * @return bool[] Array of return values, grouped by key. Each value is either
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   192
	 *                true on success, or false if cache key and group already exist.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   193
	 */
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   194
	public function add_multiple( array $data, $group = '', $expire = 0 ) {
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   195
		$values = array();
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   196
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   197
		foreach ( $data as $key => $value ) {
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   198
			$values[ $key ] = $this->add( $key, $value, $group, $expire );
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   199
		}
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   200
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   201
		return $values;
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   202
	}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   203
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   204
	/**
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   205
	 * Replaces the contents in the cache, if contents already exist.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   206
	 *
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   207
	 * @since 2.0.0
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   208
	 *
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   209
	 * @see WP_Object_Cache::set()
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   210
	 *
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   211
	 * @param int|string $key    What to call the contents in the cache.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   212
	 * @param mixed      $data   The contents to store in the cache.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   213
	 * @param string     $group  Optional. Where to group the cache contents. Default 'default'.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   214
	 * @param int        $expire Optional. When to expire the cache contents, in seconds.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   215
	 *                           Default 0 (no expiration).
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   216
	 * @return bool True if contents were replaced, false if original value does not exist.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   217
	 */
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   218
	public function replace( $key, $data, $group = 'default', $expire = 0 ) {
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   219
		if ( empty( $group ) ) {
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   220
			$group = 'default';
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   221
		}
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   222
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   223
		$id = $key;
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   224
		if ( $this->multisite && ! isset( $this->global_groups[ $group ] ) ) {
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   225
			$id = $this->blog_prefix . $key;
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   226
		}
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   227
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   228
		if ( ! $this->_exists( $id, $group ) ) {
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   229
			return false;
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   230
		}
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   231
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   232
		return $this->set( $key, $data, $group, (int) $expire );
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   233
	}
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   234
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   235
	/**
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   236
	 * Sets the data contents into the cache.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   237
	 *
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   238
	 * The cache contents are grouped by the $group parameter followed by the
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   239
	 * $key. This allows for duplicate IDs in unique groups. Therefore, naming of
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   240
	 * the group should be used with care and should follow normal function
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   241
	 * naming guidelines outside of core WordPress usage.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   242
	 *
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   243
	 * The $expire parameter is not used, because the cache will automatically
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   244
	 * expire for each time a page is accessed and PHP finishes. The method is
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   245
	 * more for cache plugins which use files.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   246
	 *
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   247
	 * @since 2.0.0
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   248
	 *
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   249
	 * @param int|string $key    What to call the contents in the cache.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   250
	 * @param mixed      $data   The contents to store in the cache.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   251
	 * @param string     $group  Optional. Where to group the cache contents. Default 'default'.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   252
	 * @param int        $expire Optional. Not used.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   253
	 * @return true Always returns true.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   254
	 */
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   255
	public function set( $key, $data, $group = 'default', $expire = 0 ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   256
		if ( empty( $group ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   257
			$group = 'default';
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   258
		}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   259
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   260
		if ( $this->multisite && ! isset( $this->global_groups[ $group ] ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   261
			$key = $this->blog_prefix . $key;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   262
		}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   263
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   264
		if ( is_object( $data ) ) {
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   265
			$data = clone $data;
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   266
		}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   267
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   268
		$this->cache[ $group ][ $key ] = $data;
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   269
		return true;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   270
	}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   271
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   272
	/**
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   273
	 * Sets multiple values to the cache in one call.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   274
	 *
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   275
	 * @since 6.0.0
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   276
	 *
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   277
	 * @param array  $data   Array of key and value to be set.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   278
	 * @param string $group  Optional. Where the cache contents are grouped. Default empty.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   279
	 * @param int    $expire Optional. When to expire the cache contents, in seconds.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   280
	 *                       Default 0 (no expiration).
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   281
	 * @return bool[] Array of return values, grouped by key. Each value is always true.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   282
	 */
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   283
	public function set_multiple( array $data, $group = '', $expire = 0 ) {
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   284
		$values = array();
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   285
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   286
		foreach ( $data as $key => $value ) {
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   287
			$values[ $key ] = $this->set( $key, $value, $group, $expire );
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   288
		}
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   289
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   290
		return $values;
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   291
	}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   292
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   293
	/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   294
	 * Retrieves the cache contents, if it exists.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   295
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   296
	 * The contents will be first attempted to be retrieved by searching by the
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   297
	 * key in the cache group. If the cache is hit (success) then the contents
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   298
	 * are returned.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   299
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   300
	 * On failure, the number of cache misses will be incremented.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   301
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   302
	 * @since 2.0.0
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   303
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   304
	 * @param int|string $key   The key under which the cache contents are stored.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   305
	 * @param string     $group Optional. Where the cache contents are grouped. Default 'default'.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   306
	 * @param bool       $force Optional. Unused. Whether to force an update of the local cache
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   307
	 *                          from the persistent cache. Default false.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   308
	 * @param bool       $found Optional. Whether the key was found in the cache (passed by reference).
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   309
	 *                          Disambiguates a return of false, a storable value. Default null.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   310
	 * @return mixed|false The cache contents on success, false on failure to retrieve contents.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   311
	 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   312
	public function get( $key, $group = 'default', $force = false, &$found = null ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   313
		if ( empty( $group ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   314
			$group = 'default';
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   315
		}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   316
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   317
		if ( $this->multisite && ! isset( $this->global_groups[ $group ] ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   318
			$key = $this->blog_prefix . $key;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   319
		}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   320
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   321
		if ( $this->_exists( $key, $group ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   322
			$found             = true;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   323
			$this->cache_hits += 1;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   324
			if ( is_object( $this->cache[ $group ][ $key ] ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   325
				return clone $this->cache[ $group ][ $key ];
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   326
			} else {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   327
				return $this->cache[ $group ][ $key ];
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   328
			}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   329
		}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   330
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   331
		$found               = false;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   332
		$this->cache_misses += 1;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   333
		return false;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   334
	}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   335
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   336
	/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   337
	 * Retrieves multiple values from the cache in one call.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   338
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   339
	 * @since 5.5.0
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   340
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   341
	 * @param array  $keys  Array of keys under which the cache contents are stored.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   342
	 * @param string $group Optional. Where the cache contents are grouped. Default 'default'.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   343
	 * @param bool   $force Optional. Whether to force an update of the local cache
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   344
	 *                      from the persistent cache. Default false.
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   345
	 * @return array Array of return values, grouped by key. Each value is either
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   346
	 *               the cache contents on success, or false on failure.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   347
	 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   348
	public function get_multiple( $keys, $group = 'default', $force = false ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   349
		$values = array();
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   350
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   351
		foreach ( $keys as $key ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   352
			$values[ $key ] = $this->get( $key, $group, $force );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   353
		}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   354
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   355
		return $values;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   356
	}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   357
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   358
	/**
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   359
	 * Removes the contents of the cache key in the group.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   360
	 *
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   361
	 * If the cache key does not exist in the group, then nothing will happen.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   362
	 *
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   363
	 * @since 2.0.0
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   364
	 *
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   365
	 * @param int|string $key        What the contents in the cache are called.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   366
	 * @param string     $group      Optional. Where the cache contents are grouped. Default 'default'.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   367
	 * @param bool       $deprecated Optional. Unused. Default false.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   368
	 * @return bool True on success, false if the contents were not deleted.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   369
	 */
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   370
	public function delete( $key, $group = 'default', $deprecated = false ) {
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   371
		if ( empty( $group ) ) {
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   372
			$group = 'default';
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   373
		}
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   374
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   375
		if ( $this->multisite && ! isset( $this->global_groups[ $group ] ) ) {
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   376
			$key = $this->blog_prefix . $key;
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   377
		}
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   378
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   379
		if ( ! $this->_exists( $key, $group ) ) {
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   380
			return false;
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   381
		}
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   382
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   383
		unset( $this->cache[ $group ][ $key ] );
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   384
		return true;
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   385
	}
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   386
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   387
	/**
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   388
	 * Deletes multiple values from the cache in one call.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   389
	 *
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   390
	 * @since 6.0.0
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   391
	 *
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   392
	 * @param array  $keys  Array of keys to be deleted.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   393
	 * @param string $group Optional. Where the cache contents are grouped. Default empty.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   394
	 * @return bool[] Array of return values, grouped by key. Each value is either
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   395
	 *                true on success, or false if the contents were not deleted.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   396
	 */
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   397
	public function delete_multiple( array $keys, $group = '' ) {
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   398
		$values = array();
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   399
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   400
		foreach ( $keys as $key ) {
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   401
			$values[ $key ] = $this->delete( $key, $group );
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   402
		}
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   403
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   404
		return $values;
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   405
	}
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   406
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   407
	/**
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   408
	 * Increments numeric cache item's value.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   409
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   410
	 * @since 3.3.0
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   411
	 *
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   412
	 * @param int|string $key    The cache key to increment.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   413
	 * @param int        $offset Optional. The amount by which to increment the item's value.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   414
	 *                           Default 1.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   415
	 * @param string     $group  Optional. The group the key is in. Default 'default'.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   416
	 * @return int|false The item's new value on success, false on failure.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   417
	 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   418
	public function incr( $key, $offset = 1, $group = 'default' ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   419
		if ( empty( $group ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   420
			$group = 'default';
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   421
		}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   422
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   423
		if ( $this->multisite && ! isset( $this->global_groups[ $group ] ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   424
			$key = $this->blog_prefix . $key;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   425
		}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   426
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   427
		if ( ! $this->_exists( $key, $group ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   428
			return false;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   429
		}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   430
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   431
		if ( ! is_numeric( $this->cache[ $group ][ $key ] ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   432
			$this->cache[ $group ][ $key ] = 0;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   433
		}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   434
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   435
		$offset = (int) $offset;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   436
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   437
		$this->cache[ $group ][ $key ] += $offset;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   438
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   439
		if ( $this->cache[ $group ][ $key ] < 0 ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   440
			$this->cache[ $group ][ $key ] = 0;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   441
		}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   442
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   443
		return $this->cache[ $group ][ $key ];
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   444
	}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   445
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   446
	/**
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   447
	 * Decrements numeric cache item's value.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   448
	 *
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   449
	 * @since 3.3.0
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   450
	 *
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   451
	 * @param int|string $key    The cache key to decrement.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   452
	 * @param int        $offset Optional. The amount by which to decrement the item's value.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   453
	 *                           Default 1.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   454
	 * @param string     $group  Optional. The group the key is in. Default 'default'.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   455
	 * @return int|false The item's new value on success, false on failure.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   456
	 */
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   457
	public function decr( $key, $offset = 1, $group = 'default' ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   458
		if ( empty( $group ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   459
			$group = 'default';
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   460
		}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   461
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   462
		if ( $this->multisite && ! isset( $this->global_groups[ $group ] ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   463
			$key = $this->blog_prefix . $key;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   464
		}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   465
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   466
		if ( ! $this->_exists( $key, $group ) ) {
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   467
			return false;
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   468
		}
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   469
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   470
		if ( ! is_numeric( $this->cache[ $group ][ $key ] ) ) {
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   471
			$this->cache[ $group ][ $key ] = 0;
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   472
		}
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   473
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   474
		$offset = (int) $offset;
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   475
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   476
		$this->cache[ $group ][ $key ] -= $offset;
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   477
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   478
		if ( $this->cache[ $group ][ $key ] < 0 ) {
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   479
			$this->cache[ $group ][ $key ] = 0;
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   480
		}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   481
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   482
		return $this->cache[ $group ][ $key ];
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   483
	}
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   484
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   485
	/**
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   486
	 * Clears the object cache of all data.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   487
	 *
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   488
	 * @since 2.0.0
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   489
	 *
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   490
	 * @return true Always returns true.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   491
	 */
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   492
	public function flush() {
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   493
		$this->cache = array();
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   494
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   495
		return true;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   496
	}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   497
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   498
	/**
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   499
	 * Sets the list of global cache groups.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   500
	 *
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   501
	 * @since 3.0.0
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   502
	 *
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   503
	 * @param string|string[] $groups List of groups that are global.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   504
	 */
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   505
	public function add_global_groups( $groups ) {
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   506
		$groups = (array) $groups;
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   507
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   508
		$groups              = array_fill_keys( $groups, true );
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   509
		$this->global_groups = array_merge( $this->global_groups, $groups );
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   510
	}
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   511
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   512
	/**
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   513
	 * Switches the internal blog ID.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   514
	 *
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   515
	 * This changes the blog ID used to create keys in blog specific groups.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   516
	 *
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   517
	 * @since 3.5.0
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   518
	 *
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   519
	 * @param int $blog_id Blog ID.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   520
	 */
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   521
	public function switch_to_blog( $blog_id ) {
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   522
		$blog_id           = (int) $blog_id;
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   523
		$this->blog_prefix = $this->multisite ? $blog_id . ':' : '';
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   524
	}
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   525
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   526
	/**
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   527
	 * Resets cache keys.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   528
	 *
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   529
	 * @since 3.0.0
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   530
	 *
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   531
	 * @deprecated 3.5.0 Use WP_Object_Cache::switch_to_blog()
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   532
	 * @see switch_to_blog()
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   533
	 */
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   534
	public function reset() {
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   535
		_deprecated_function( __FUNCTION__, '3.5.0', 'WP_Object_Cache::switch_to_blog()' );
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   536
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   537
		// Clear out non-global caches since the blog ID has changed.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   538
		foreach ( array_keys( $this->cache ) as $group ) {
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   539
			if ( ! isset( $this->global_groups[ $group ] ) ) {
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   540
				unset( $this->cache[ $group ] );
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   541
			}
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   542
		}
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   543
	}
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   544
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   545
	/**
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   546
	 * Echoes the stats of the caching.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   547
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   548
	 * Gives the cache hits, and cache misses. Also prints every cached group,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   549
	 * key and the data.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   550
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   551
	 * @since 2.0.0
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   552
	 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   553
	public function stats() {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   554
		echo '<p>';
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   555
		echo "<strong>Cache Hits:</strong> {$this->cache_hits}<br />";
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   556
		echo "<strong>Cache Misses:</strong> {$this->cache_misses}<br />";
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   557
		echo '</p>';
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   558
		echo '<ul>';
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   559
		foreach ( $this->cache as $group => $cache ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   560
			echo '<li><strong>Group:</strong> ' . esc_html( $group ) . ' - ( ' . number_format( strlen( serialize( $cache ) ) / KB_IN_BYTES, 2 ) . 'k )</li>';
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   561
		}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   562
		echo '</ul>';
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   563
	}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents:
diff changeset
   564
}