wp/wp-includes/cache.php
author ymh <ymh.work@gmail.com>
Mon, 14 Oct 2019 17:39:30 +0200
changeset 7 cf61fcea0001
parent 5 5e2f62d02dcd
child 9 177826044cd9
permissions -rw-r--r--
resynchronize code repo with production
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
 * Object Cache API
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
     5
 * @link https://codex.wordpress.org/Class_Reference/WP_Object_Cache
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
 * @package WordPress
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
 * @subpackage Cache
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
 * Adds data to the cache, if the cache key doesn't already exist.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
 * @since 2.0.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    15
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
 * @see WP_Object_Cache::add()
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    17
 * @global WP_Object_Cache $wp_object_cache Object cache global instance.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    19
 * @param int|string $key    The cache key to use for retrieval later.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    20
 * @param mixed      $data   The data to add to the cache.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    21
 * @param string     $group  Optional. The group to add the cache to. Enables the same key
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    22
 *                           to be used across groups. Default empty.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    23
 * @param int        $expire Optional. When the cache data should expire, in seconds.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    24
 *                           Default 0 (no expiration).
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    25
 * @return bool False if cache key and group already exist, true on success.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
function wp_cache_add( $key, $data, $group = '', $expire = 0 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
	global $wp_object_cache;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
	return $wp_object_cache->add( $key, $data, $group, (int) $expire );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
 * Closes the cache.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
 * This function has ceased to do anything since WordPress 2.5. The
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    37
 * functionality was removed along with the rest of the persistent cache.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    38
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    39
 * This does not mean that plugins can't implement this function when they need
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    40
 * to make sure that the cache is cleaned up after WordPress no longer needs it.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
 * @since 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    44
 * @return true Always returns true.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
function wp_cache_close() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
	return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    51
 * Decrements numeric cache item's value.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
 * @since 3.3.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    54
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
 * @see WP_Object_Cache::decr()
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    56
 * @global WP_Object_Cache $wp_object_cache Object cache global instance.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    58
 * @param int|string $key    The cache key to decrement.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    59
 * @param int        $offset Optional. The amount by which to decrement the item's value. Default 1.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    60
 * @param string     $group  Optional. The group the key is in. Default empty.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
 * @return false|int False on failure, the item's new value on success.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
function wp_cache_decr( $key, $offset = 1, $group = '' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
	global $wp_object_cache;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
	return $wp_object_cache->decr( $key, $offset, $group );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
 * Removes the cache contents matching key and group.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
 * @since 2.0.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    73
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
 * @see WP_Object_Cache::delete()
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    75
 * @global WP_Object_Cache $wp_object_cache Object cache global instance.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    77
 * @param int|string $key   What the contents in the cache are called.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    78
 * @param string     $group Optional. Where the cache contents are grouped. Default empty.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    79
 * @return bool True on successful removal, false on failure.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    81
function wp_cache_delete( $key, $group = '' ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
	global $wp_object_cache;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    84
	return $wp_object_cache->delete($key, $group);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
 * Removes all cache items.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
 * @since 2.0.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    91
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
 * @see WP_Object_Cache::flush()
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    93
 * @global WP_Object_Cache $wp_object_cache Object cache global instance.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    94
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    95
 * @return bool False on failure, true on success
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    96
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    97
function wp_cache_flush() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    98
	global $wp_object_cache;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    99
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
	return $wp_object_cache->flush();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   102
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   104
 * Retrieves the cache contents from the cache by key and group.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   106
 * @since 2.0.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   107
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
 * @see WP_Object_Cache::get()
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   109
 * @global WP_Object_Cache $wp_object_cache Object cache global instance.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   110
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   111
 * @param int|string  $key    The key under which the cache contents are stored.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   112
 * @param string      $group  Optional. Where the cache contents are grouped. Default empty.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   113
 * @param bool        $force  Optional. Whether to force an update of the local cache from the persistent
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   114
 *                            cache. Default false.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   115
 * @param bool        $found  Optional. Whether the key was found in the cache (passed by reference).
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   116
 *                            Disambiguates a return of false, a storable value. Default null.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
 * @return bool|mixed False on failure to retrieve contents or the cache
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   118
 *		              contents on success
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   119
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   120
function wp_cache_get( $key, $group = '', $force = false, &$found = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   121
	global $wp_object_cache;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   122
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   123
	return $wp_object_cache->get( $key, $group, $force, $found );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   124
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   125
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   127
 * Increment numeric cache item's value
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   128
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   129
 * @since 3.3.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   130
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
 * @see WP_Object_Cache::incr()
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   132
 * @global WP_Object_Cache $wp_object_cache Object cache global instance.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   133
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   134
 * @param int|string $key    The key for the cache contents that should be incremented.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   135
 * @param int        $offset Optional. The amount by which to increment the item's value. Default 1.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   136
 * @param string     $group  Optional. The group the key is in. Default empty.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   137
 * @return false|int False on failure, the item's new value on success.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   138
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   139
function wp_cache_incr( $key, $offset = 1, $group = '' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   140
	global $wp_object_cache;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   141
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   142
	return $wp_object_cache->incr( $key, $offset, $group );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   143
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   144
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   145
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   146
 * Sets up Object Cache Global and assigns it.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   147
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   148
 * @since 2.0.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   149
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   150
 * @global WP_Object_Cache $wp_object_cache
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   151
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   152
function wp_cache_init() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   153
	$GLOBALS['wp_object_cache'] = new WP_Object_Cache();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   154
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   155
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   156
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   157
 * Replaces the contents of the cache with new data.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   158
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   159
 * @since 2.0.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   160
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   161
 * @see WP_Object_Cache::replace()
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   162
 * @global WP_Object_Cache $wp_object_cache Object cache global instance.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   164
 * @param int|string $key    The key for the cache data that should be replaced.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   165
 * @param mixed      $data   The new data to store in the cache.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   166
 * @param string     $group  Optional. The group for the cache data that should be replaced.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   167
 *                           Default empty.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   168
 * @param int        $expire Optional. When to expire the cache contents, in seconds.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   169
 *                           Default 0 (no expiration).
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   170
 * @return bool False if original value does not exist, true if contents were replaced
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   171
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   172
function wp_cache_replace( $key, $data, $group = '', $expire = 0 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   173
	global $wp_object_cache;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   174
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   175
	return $wp_object_cache->replace( $key, $data, $group, (int) $expire );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   176
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   177
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   178
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   179
 * Saves the data to the cache.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   180
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   181
 * Differs from wp_cache_add() and wp_cache_replace() in that it will always write data.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   182
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   183
 * @since 2.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   184
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   185
 * @see WP_Object_Cache::set()
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   186
 * @global WP_Object_Cache $wp_object_cache Object cache global instance.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   187
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   188
 * @param int|string $key    The cache key to use for retrieval later.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   189
 * @param mixed      $data   The contents to store in the cache.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   190
 * @param string     $group  Optional. Where to group the cache contents. Enables the same key
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   191
 *                           to be used across groups. Default empty.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   192
 * @param int        $expire Optional. When to expire the cache contents, in seconds.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   193
 *                           Default 0 (no expiration).
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   194
 * @return bool False on failure, true on success
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   195
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   196
function wp_cache_set( $key, $data, $group = '', $expire = 0 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   197
	global $wp_object_cache;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   198
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   199
	return $wp_object_cache->set( $key, $data, $group, (int) $expire );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   200
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   201
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   202
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   203
 * Switches the internal blog ID.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   204
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   205
 * This changes the blog id used to create keys in blog specific groups.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   206
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   207
 * @since 3.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   208
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   209
 * @see WP_Object_Cache::switch_to_blog()
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   210
 * @global WP_Object_Cache $wp_object_cache Object cache global instance.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   211
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   212
 * @param int $blog_id Site ID.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   213
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   214
function wp_cache_switch_to_blog( $blog_id ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   215
	global $wp_object_cache;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   216
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   217
	$wp_object_cache->switch_to_blog( $blog_id );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   218
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   219
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   220
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   221
 * Adds a group or set of groups to the list of global groups.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   222
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   223
 * @since 2.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   224
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   225
 * @see WP_Object_Cache::add_global_groups()
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   226
 * @global WP_Object_Cache $wp_object_cache Object cache global instance.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   227
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   228
 * @param string|array $groups A group or an array of groups to add.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   229
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   230
function wp_cache_add_global_groups( $groups ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   231
	global $wp_object_cache;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   232
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   233
	$wp_object_cache->add_global_groups( $groups );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   234
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   235
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   236
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   237
 * Adds a group or set of groups to the list of non-persistent groups.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   238
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   239
 * @since 2.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   240
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   241
 * @param string|array $groups A group or an array of groups to add.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   242
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   243
function wp_cache_add_non_persistent_groups( $groups ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   244
	// Default cache doesn't persist so nothing to do here.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   245
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   246
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   247
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   248
 * Reset internal cache keys and structures.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   249
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   250
 * If the cache back end uses global blog or site IDs as part of its cache keys,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   251
 * this function instructs the back end to reset those keys and perform any cleanup
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   252
 * since blog or site IDs have changed since cache init.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   253
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   254
 * This function is deprecated. Use wp_cache_switch_to_blog() instead of this
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   255
 * function when preparing the cache for a blog switch. For clearing the cache
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   256
 * during unit tests, consider using wp_cache_init(). wp_cache_init() is not
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   257
 * recommended outside of unit tests as the performance penalty for using it is
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   258
 * high.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   259
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   260
 * @since 2.6.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   261
 * @deprecated 3.5.0 WP_Object_Cache::reset()
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   262
 * @see WP_Object_Cache::reset()
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   263
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   264
 * @global WP_Object_Cache $wp_object_cache Object cache global instance.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   265
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   266
function wp_cache_reset() {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   267
	_deprecated_function( __FUNCTION__, '3.5.0', 'WP_Object_Cache::reset()' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   268
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   269
	global $wp_object_cache;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   270
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   271
	$wp_object_cache->reset();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   272
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   273
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   274
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   275
 * Core class that implements an object cache.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   276
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   277
 * The WordPress Object Cache is used to save on trips to the database. The
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   278
 * Object Cache stores all of the cache data to memory and makes the cache
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   279
 * contents available by using a key, which is used to name and later retrieve
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   280
 * the cache contents.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   281
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   282
 * The Object Cache can be replaced by other caching mechanisms by placing files
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   283
 * in the wp-content folder which is looked at in wp-settings. If that file
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   284
 * exists, then this file will not be included.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   285
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   286
 * @since 2.0.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   287
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   288
class WP_Object_Cache {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   289
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   290
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   291
	 * Holds the cached objects.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   292
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   293
	 * @since 2.0.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   294
	 * @var array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   295
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   296
	private $cache = array();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   297
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   298
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   299
	 * The amount of times the cache data was already stored in the cache.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   300
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   301
	 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   302
	 * @var int
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   303
	 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   304
	public $cache_hits = 0;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   305
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   306
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   307
	 * Amount of times the cache did not have the request in cache.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   308
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   309
	 * @since 2.0.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   310
	 * @var int
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   311
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   312
	public $cache_misses = 0;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   313
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   314
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   315
	 * List of global cache groups.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   316
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   317
	 * @since 3.0.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   318
	 * @var array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   319
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   320
	protected $global_groups = array();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   321
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   322
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   323
	 * The blog prefix to prepend to keys in non-global groups.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   324
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   325
	 * @since 3.5.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   326
	 * @var int
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   327
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   328
	private $blog_prefix;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   329
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   330
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   331
	 * Holds the value of is_multisite().
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   332
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   333
	 * @since 3.5.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   334
	 * @var bool
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   335
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   336
	private $multisite;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   337
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   338
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   339
	 * Makes private properties readable for backward compatibility.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   340
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   341
	 * @since 4.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   342
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   343
	 * @param string $name Property to get.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   344
	 * @return mixed Property.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   345
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   346
	public function __get( $name ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   347
		return $this->$name;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   348
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   349
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   350
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   351
	 * Makes private properties settable for backward compatibility.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   352
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   353
	 * @since 4.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   354
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   355
	 * @param string $name  Property to set.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   356
	 * @param mixed  $value Property value.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   357
	 * @return mixed Newly-set property.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   358
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   359
	public function __set( $name, $value ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   360
		return $this->$name = $value;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   361
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   362
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   363
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   364
	 * Makes private properties checkable for backward compatibility.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   365
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   366
	 * @since 4.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   367
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   368
	 * @param string $name Property to check if set.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   369
	 * @return bool Whether the property is set.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   370
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   371
	public function __isset( $name ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   372
		return isset( $this->$name );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   373
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   374
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   375
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   376
	 * Makes private properties un-settable for backward compatibility.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   377
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   378
	 * @since 4.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   379
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   380
	 * @param string $name Property to unset.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   381
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   382
	public function __unset( $name ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   383
		unset( $this->$name );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   384
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   385
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   386
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   387
	 * Adds data to the cache if it doesn't already exist.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   388
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   389
	 * @since 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   390
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   391
	 * @uses WP_Object_Cache::_exists() Checks to see if the cache already has data.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   392
	 * @uses WP_Object_Cache::set()     Sets the data after the checking the cache
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   393
	 *		                            contents existence.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   394
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   395
	 * @param int|string $key    What to call the contents in the cache.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   396
	 * @param mixed      $data   The contents to store in the cache.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   397
	 * @param string     $group  Optional. Where to group the cache contents. Default 'default'.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   398
	 * @param int        $expire Optional. When to expire the cache contents. Default 0 (no expiration).
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   399
	 * @return bool False if cache key and group already exist, true on success
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   400
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   401
	public function add( $key, $data, $group = 'default', $expire = 0 ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   402
		if ( wp_suspend_cache_addition() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   403
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   404
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   405
		if ( empty( $group ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   406
			$group = 'default';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   407
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   408
		$id = $key;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   409
		if ( $this->multisite && ! isset( $this->global_groups[ $group ] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   410
			$id = $this->blog_prefix . $key;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   411
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   412
		if ( $this->_exists( $id, $group ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   413
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   414
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   415
		return $this->set( $key, $data, $group, (int) $expire );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   416
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   417
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   418
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   419
	 * Sets the list of global cache groups.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   420
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   421
	 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   422
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   423
	 * @param array $groups List of groups that are global.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   424
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   425
	public function add_global_groups( $groups ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   426
		$groups = (array) $groups;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   427
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   428
		$groups = array_fill_keys( $groups, true );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   429
		$this->global_groups = array_merge( $this->global_groups, $groups );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   430
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   431
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   432
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   433
	 * Decrements numeric cache item's value.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   434
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   435
	 * @since 3.3.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   436
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   437
	 * @param int|string $key    The cache key to decrement.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   438
	 * @param int        $offset Optional. The amount by which to decrement the item's value. Default 1.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   439
	 * @param string     $group  Optional. The group the key is in. Default 'default'.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   440
	 * @return false|int False on failure, the item's new value on success.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   441
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   442
	public function decr( $key, $offset = 1, $group = 'default' ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   443
		if ( empty( $group ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   444
			$group = 'default';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   445
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   446
		if ( $this->multisite && ! isset( $this->global_groups[ $group ] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   447
			$key = $this->blog_prefix . $key;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   448
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   449
		if ( ! $this->_exists( $key, $group ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   450
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   451
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   452
		if ( ! is_numeric( $this->cache[ $group ][ $key ] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   453
			$this->cache[ $group ][ $key ] = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   454
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   455
		$offset = (int) $offset;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   456
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   457
		$this->cache[ $group ][ $key ] -= $offset;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   458
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   459
		if ( $this->cache[ $group ][ $key ] < 0 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   460
			$this->cache[ $group ][ $key ] = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   461
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   462
		return $this->cache[ $group ][ $key ];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   463
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   464
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   465
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   466
	 * Removes the contents of the cache key in the group.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   467
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   468
	 * If the cache key does not exist in the group, then nothing will happen.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   469
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   470
	 * @since 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   471
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   472
	 * @param int|string $key        What the contents in the cache are called.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   473
	 * @param string     $group      Optional. Where the cache contents are grouped. Default 'default'.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   474
	 * @param bool       $deprecated Optional. Unused. Default false.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   475
	 * @return bool False if the contents weren't deleted and true on success.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   476
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   477
	public function delete( $key, $group = 'default', $deprecated = false ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   478
		if ( empty( $group ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   479
			$group = 'default';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   480
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   481
		if ( $this->multisite && ! isset( $this->global_groups[ $group ] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   482
			$key = $this->blog_prefix . $key;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   483
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   484
		if ( ! $this->_exists( $key, $group ) )
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   485
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   486
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   487
		unset( $this->cache[$group][$key] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   488
		return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   489
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   490
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   491
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   492
	 * Clears the object cache of all data.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   493
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   494
	 * @since 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   495
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   496
	 * @return true Always returns true.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   497
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   498
	public function flush() {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   499
		$this->cache = array();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   500
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   501
		return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   502
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   503
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   504
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   505
	 * Retrieves the cache contents, if it exists.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   506
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   507
	 * The contents will be first attempted to be retrieved by searching by the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   508
	 * key in the cache group. If the cache is hit (success) then the contents
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   509
	 * are returned.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   510
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   511
	 * On failure, the number of cache misses will be incremented.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   512
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   513
	 * @since 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   514
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   515
	 * @param int|string $key    What the contents in the cache are called.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   516
	 * @param string     $group  Optional. Where the cache contents are grouped. Default 'default'.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   517
	 * @param string     $force  Optional. Unused. Whether to force a refetch rather than relying on the local
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   518
	 *                           cache. Default false.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   519
	 * @param bool        $found  Optional. Whether the key was found in the cache (passed by reference).
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   520
	 *                            Disambiguates a return of false, a storable value. Default null.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   521
	 * @return false|mixed False on failure to retrieve contents or the cache contents on success.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   522
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   523
	public function get( $key, $group = 'default', $force = false, &$found = null ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   524
		if ( empty( $group ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   525
			$group = 'default';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   526
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   527
		if ( $this->multisite && ! isset( $this->global_groups[ $group ] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   528
			$key = $this->blog_prefix . $key;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   529
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   530
		if ( $this->_exists( $key, $group ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   531
			$found = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   532
			$this->cache_hits += 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   533
			if ( is_object($this->cache[$group][$key]) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   534
				return clone $this->cache[$group][$key];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   535
			else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   536
				return $this->cache[$group][$key];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   537
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   538
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   539
		$found = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   540
		$this->cache_misses += 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   541
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   542
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   543
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   544
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   545
	 * Increments numeric cache item's value.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   546
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   547
	 * @since 3.3.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   548
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   549
	 * @param int|string $key    The cache key to increment
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   550
	 * @param int        $offset Optional. The amount by which to increment the item's value. Default 1.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   551
	 * @param string     $group  Optional. The group the key is in. Default 'default'.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   552
	 * @return false|int False on failure, the item's new value on success.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   553
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   554
	public function incr( $key, $offset = 1, $group = 'default' ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   555
		if ( empty( $group ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   556
			$group = 'default';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   557
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   558
		if ( $this->multisite && ! isset( $this->global_groups[ $group ] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   559
			$key = $this->blog_prefix . $key;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   560
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   561
		if ( ! $this->_exists( $key, $group ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   562
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   563
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   564
		if ( ! is_numeric( $this->cache[ $group ][ $key ] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   565
			$this->cache[ $group ][ $key ] = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   566
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   567
		$offset = (int) $offset;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   568
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   569
		$this->cache[ $group ][ $key ] += $offset;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   570
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   571
		if ( $this->cache[ $group ][ $key ] < 0 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   572
			$this->cache[ $group ][ $key ] = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   573
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   574
		return $this->cache[ $group ][ $key ];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   575
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   576
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   577
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   578
	 * Replaces the contents in the cache, if contents already exist.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   579
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   580
	 * @since 2.0.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   581
	 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   582
	 * @see WP_Object_Cache::set()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   583
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   584
	 * @param int|string $key    What to call the contents in the cache.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   585
	 * @param mixed      $data   The contents to store in the cache.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   586
	 * @param string     $group  Optional. Where to group the cache contents. Default 'default'.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   587
	 * @param int        $expire Optional. When to expire the cache contents. Default 0 (no expiration).
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   588
	 * @return bool False if not exists, true if contents were replaced.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   589
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   590
	public function replace( $key, $data, $group = 'default', $expire = 0 ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   591
		if ( empty( $group ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   592
			$group = 'default';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   593
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   594
		$id = $key;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   595
		if ( $this->multisite && ! isset( $this->global_groups[ $group ] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   596
			$id = $this->blog_prefix . $key;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   597
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   598
		if ( ! $this->_exists( $id, $group ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   599
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   600
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   601
		return $this->set( $key, $data, $group, (int) $expire );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   602
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   603
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   604
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   605
	 * Resets cache keys.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   606
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   607
	 * @since 3.0.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   608
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   609
	 * @deprecated 3.5.0 Use switch_to_blog()
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   610
	 * @see switch_to_blog()
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   611
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   612
	public function reset() {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   613
		_deprecated_function( __FUNCTION__, '3.5.0', 'switch_to_blog()' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   614
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   615
		// Clear out non-global caches since the blog ID has changed.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   616
		foreach ( array_keys( $this->cache ) as $group ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   617
			if ( ! isset( $this->global_groups[ $group ] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   618
				unset( $this->cache[ $group ] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   619
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   620
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   621
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   622
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   623
	 * Sets the data contents into the cache.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   624
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   625
	 * The cache contents is grouped by the $group parameter followed by the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   626
	 * $key. This allows for duplicate ids in unique groups. Therefore, naming of
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   627
	 * the group should be used with care and should follow normal function
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   628
	 * naming guidelines outside of core WordPress usage.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   629
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   630
	 * The $expire parameter is not used, because the cache will automatically
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   631
	 * expire for each time a page is accessed and PHP finishes. The method is
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   632
	 * more for cache plugins which use files.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   633
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   634
	 * @since 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   635
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   636
	 * @param int|string $key    What to call the contents in the cache.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   637
	 * @param mixed      $data   The contents to store in the cache.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   638
	 * @param string     $group  Optional. Where to group the cache contents. Default 'default'.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   639
	 * @param int        $expire Not Used.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   640
	 * @return true Always returns true.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   641
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   642
	public function set( $key, $data, $group = 'default', $expire = 0 ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   643
		if ( empty( $group ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   644
			$group = 'default';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   645
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   646
		if ( $this->multisite && ! isset( $this->global_groups[ $group ] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   647
			$key = $this->blog_prefix . $key;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   648
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   649
		if ( is_object( $data ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   650
			$data = clone $data;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   651
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   652
		$this->cache[$group][$key] = $data;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   653
		return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   654
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   655
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   656
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   657
	 * Echoes the stats of the caching.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   658
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   659
	 * Gives the cache hits, and cache misses. Also prints every cached group,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   660
	 * key and the data.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   661
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   662
	 * @since 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   663
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   664
	public function stats() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   665
		echo "<p>";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   666
		echo "<strong>Cache Hits:</strong> {$this->cache_hits}<br />";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   667
		echo "<strong>Cache Misses:</strong> {$this->cache_misses}<br />";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   668
		echo "</p>";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   669
		echo '<ul>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   670
		foreach ($this->cache as $group => $cache) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   671
			echo "<li><strong>Group:</strong> $group - ( " . number_format( strlen( serialize( $cache ) ) / KB_IN_BYTES, 2 ) . 'k )</li>';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   672
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   673
		echo '</ul>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   674
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   675
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   676
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   677
	 * Switches the internal blog ID.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   678
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   679
	 * This changes the blog ID used to create keys in blog specific groups.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   680
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   681
	 * @since 3.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   682
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   683
	 * @param int $blog_id Blog ID.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   684
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   685
	public function switch_to_blog( $blog_id ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   686
		$blog_id = (int) $blog_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   687
		$this->blog_prefix = $this->multisite ? $blog_id . ':' : '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   688
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   689
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   690
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   691
	 * Serves as a utility function to determine whether a key exists in the cache.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   692
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   693
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   694
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   695
	 * @param int|string $key   Cache key to check for existence.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   696
	 * @param string     $group Cache group for the key existence check.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   697
	 * @return bool Whether the key exists in the cache for the given group.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   698
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   699
	protected function _exists( $key, $group ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   700
		return isset( $this->cache[ $group ] ) && ( isset( $this->cache[ $group ][ $key ] ) || array_key_exists( $key, $this->cache[ $group ] ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   701
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   702
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   703
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   704
	 * Sets up object properties; PHP 5 style constructor.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   705
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   706
	 * @since 2.0.8
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   707
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   708
	public function __construct() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   709
		$this->multisite = is_multisite();
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   710
		$this->blog_prefix =  $this->multisite ? get_current_blog_id() . ':' : '';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   711
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   712
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   713
		/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   714
		 * @todo This should be moved to the PHP4 style constructor, PHP5
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   715
		 * already calls __destruct()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   716
		 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   717
		register_shutdown_function( array( $this, '__destruct' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   718
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   719
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   720
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   721
	 * Saves the object cache before object is completely destroyed.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   722
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   723
	 * Called upon object destruction, which should be when PHP ends.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   724
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   725
	 * @since 2.0.8
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   726
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   727
	 * @return true Always returns true.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   728
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   729
	public function __destruct() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   730
		return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   731
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   732
}