~canonical-sysadmins/wordpress/4.5.3

« back to all changes in this revision

Viewing changes to wp-includes/cache.php

  • Committer: Manuel Seelaus
  • Date: 2015-12-09 17:47:18 UTC
  • mfrom: (1.1.11 upstream)
  • Revision ID: manuel.seelaus@canonical.com-20151209174718-coxethm2swbeqksy
Merge WP4.4 from upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
 *
14
14
 * @since 2.0.0
15
15
 *
16
 
 * @global WP_Object_Cache $wp_object_cache
 
16
 * @see WP_Object_Cache::add()
 
17
 * @global WP_Object_Cache $wp_object_cache Object cache global instance.
17
18
 *
18
 
 * @param int|string $key The cache key to use for retrieval later
19
 
 * @param mixed $data The data to add to the cache store
20
 
 * @param string $group The group to add the cache to
21
 
 * @param int $expire When the cache data should be expired
22
 
 * @return bool False if cache key and group already exist, true on success
 
19
 * @param int|string $key    The cache key to use for retrieval later.
 
20
 * @param mixed      $data   The data to add to the cache.
 
21
 * @param string     $group  Optional. The group to add the cache to. Enables the same key
 
22
 *                           to be used across groups. Default empty.
 
23
 * @param int        $expire Optional. When the cache data should expire, in seconds.
 
24
 *                           Default 0 (no expiration).
 
25
 * @return bool False if cache key and group already exist, true on success.
23
26
 */
24
27
function wp_cache_add( $key, $data, $group = '', $expire = 0 ) {
25
28
        global $wp_object_cache;
31
34
 * Closes the cache.
32
35
 *
33
36
 * This function has ceased to do anything since WordPress 2.5. The
34
 
 * functionality was removed along with the rest of the persistent cache. This
35
 
 * does not mean that plugins can't implement this function when they need to
36
 
 * make sure that the cache is cleaned up after WordPress no longer needs it.
 
37
 * functionality was removed along with the rest of the persistent cache.
 
38
 *
 
39
 * This does not mean that plugins can't implement this function when they need
 
40
 * to make sure that the cache is cleaned up after WordPress no longer needs it.
37
41
 *
38
42
 * @since 2.0.0
39
43
 *
40
 
 * @return true Always returns True
 
44
 * @return true Always returns true.
41
45
 */
42
46
function wp_cache_close() {
43
47
        return true;
44
48
}
45
49
 
46
50
/**
47
 
 * Decrement numeric cache item's value
 
51
 * Decrements numeric cache item's value.
48
52
 *
49
53
 * @since 3.3.0
50
54
 *
51
 
 * @global WP_Object_Cache $wp_object_cache
 
55
 * @see WP_Object_Cache::decr()
 
56
 * @global WP_Object_Cache $wp_object_cache Object cache global instance.
52
57
 *
53
 
 * @param int|string $key The cache key to increment
54
 
 * @param int $offset The amount by which to decrement the item's value. Default is 1.
55
 
 * @param string $group The group the key is in.
 
58
 * @param int|string $key    The cache key to decrement.
 
59
 * @param int        $offset Optional. The amount by which to decrement the item's value. Default 1.
 
60
 * @param string     $group  Optional. The group the key is in. Default empty.
56
61
 * @return false|int False on failure, the item's new value on success.
57
62
 */
58
63
function wp_cache_decr( $key, $offset = 1, $group = '' ) {
66
71
 *
67
72
 * @since 2.0.0
68
73
 *
69
 
 * @global WP_Object_Cache $wp_object_cache
 
74
 * @see WP_Object_Cache::delete()
 
75
 * @global WP_Object_Cache $wp_object_cache Object cache global instance.
70
76
 *
71
 
 * @param int|string $key What the contents in the cache are called
72
 
 * @param string $group Where the cache contents are grouped
73
 
 * @return bool True on successful removal, false on failure
 
77
 * @param int|string $key   What the contents in the cache are called.
 
78
 * @param string     $group Optional. Where the cache contents are grouped. Default empty.
 
79
 * @return bool True on successful removal, false on failure.
74
80
 */
75
 
function wp_cache_delete($key, $group = '') {
 
81
function wp_cache_delete( $key, $group = '' ) {
76
82
        global $wp_object_cache;
77
83
 
78
84
        return $wp_object_cache->delete($key, $group);
83
89
 *
84
90
 * @since 2.0.0
85
91
 *
86
 
 * @global WP_Object_Cache $wp_object_cache
 
92
 * @see WP_Object_Cache::flush()
 
93
 * @global WP_Object_Cache $wp_object_cache Object cache global instance.
87
94
 *
88
95
 * @return bool False on failure, true on success
89
96
 */
98
105
 *
99
106
 * @since 2.0.0
100
107
 *
101
 
 * @global WP_Object_Cache $wp_object_cache
 
108
 * @see WP_Object_Cache::get()
 
109
 * @global WP_Object_Cache $wp_object_cache Object cache global instance.
102
110
 *
103
 
 * @param int|string $key What the contents in the cache are called
104
 
 * @param string $group Where the cache contents are grouped
105
 
 * @param bool $force Whether to force an update of the local cache from the persistent cache (default is false)
106
 
 * @param bool &$found Whether key was found in the cache. Disambiguates a return of false, a storable value.
 
111
 * @param int|string  $key    The key under which the cache contents are stored.
 
112
 * @param string      $group  Optional. Where the cache contents are grouped. Default empty.
 
113
 * @param bool        $force  Optional. Whether to force an update of the local cache from the persistent
 
114
 *                            cache. Default false.
 
115
 * @param bool        &$found Optional. Whether the key was found in the cache. Disambiguates a return of false,
 
116
 *                            a storable value. Passed by reference. Default null.
107
117
 * @return bool|mixed False on failure to retrieve contents or the cache
108
118
 *                            contents on success
109
119
 */
118
128
 *
119
129
 * @since 3.3.0
120
130
 *
121
 
 * @global WP_Object_Cache $wp_object_cache
 
131
 * @see WP_Object_Cache::incr()
 
132
 * @global WP_Object_Cache $wp_object_cache Object cache global instance.
122
133
 *
123
 
 * @param int|string $key The cache key to increment
124
 
 * @param int $offset The amount by which to increment the item's value. Default is 1.
125
 
 * @param string $group The group the key is in.
 
134
 * @param int|string $key    The key for the cache contents that should be incremented.
 
135
 * @param int        $offset Optional. The amount by which to increment the item's value. Default 1.
 
136
 * @param string     $group  Optional. The group the key is in. Default empty.
126
137
 * @return false|int False on failure, the item's new value on success.
127
138
 */
128
139
function wp_cache_incr( $key, $offset = 1, $group = '' ) {
147
158
 *
148
159
 * @since 2.0.0
149
160
 *
150
 
 * @global WP_Object_Cache $wp_object_cache
 
161
 * @see WP_Object_Cache::replace()
 
162
 * @global WP_Object_Cache $wp_object_cache Object cache global instance.
151
163
 *
152
 
 * @param int|string $key What to call the contents in the cache
153
 
 * @param mixed $data The contents to store in the cache
154
 
 * @param string $group Where to group the cache contents
155
 
 * @param int $expire When to expire the cache contents
156
 
 * @return bool False if not exists, true if contents were replaced
 
164
 * @param int|string $key    The key for the cache data that should be replaced.
 
165
 * @param mixed      $data   The new data to store in the cache.
 
166
 * @param string     $group  Optional. The group for the cache data that should be replaced.
 
167
 *                           Default empty.
 
168
 * @param int        $expire Optional. When to expire the cache contents, in seconds.
 
169
 *                           Default 0 (no expiration).
 
170
 * @return bool False if original value does not exist, true if contents were replaced
157
171
 */
158
172
function wp_cache_replace( $key, $data, $group = '', $expire = 0 ) {
159
173
        global $wp_object_cache;
164
178
/**
165
179
 * Saves the data to the cache.
166
180
 *
 
181
 * Differs from wp_cache_add() and wp_cache_replace() in that it will always write data.
 
182
 *
167
183
 * @since 2.0.0
168
184
 *
169
 
 * @global WP_Object_Cache $wp_object_cache
 
185
 * @see WP_Object_Cache::set()
 
186
 * @global WP_Object_Cache $wp_object_cache Object cache global instance.
170
187
 *
171
 
 * @param int|string $key What to call the contents in the cache
172
 
 * @param mixed $data The contents to store in the cache
173
 
 * @param string $group Where to group the cache contents
174
 
 * @param int $expire When to expire the cache contents
 
188
 * @param int|string $key    The cache key to use for retrieval later.
 
189
 * @param mixed      $data   The contents to store in the cache.
 
190
 * @param string     $group  Optional. Where to group the cache contents. Enables the same key
 
191
 *                           to be used across groups. Default empty.
 
192
 * @param int        $expire Optional. When to expire the cache contents, in seconds.
 
193
 *                           Default 0 (no expiration).
175
194
 * @return bool False on failure, true on success
176
195
 */
177
196
function wp_cache_set( $key, $data, $group = '', $expire = 0 ) {
181
200
}
182
201
 
183
202
/**
184
 
 * Switch the interal blog id.
 
203
 * Switches the interal blog ID.
185
204
 *
186
205
 * This changes the blog id used to create keys in blog specific groups.
187
206
 *
188
207
 * @since 3.5.0
189
208
 *
190
 
 * @global WP_Object_Cache $wp_object_cache
 
209
 * @see WP_Object_Cache::switch_to_blog()
 
210
 * @global WP_Object_Cache $wp_object_cache Object cache global instance.
191
211
 *
192
 
 * @param int $blog_id Blog ID
 
212
 * @param int $blog_id Blog ID.
193
213
 */
194
214
function wp_cache_switch_to_blog( $blog_id ) {
195
215
        global $wp_object_cache;
202
222
 *
203
223
 * @since 2.6.0
204
224
 *
205
 
 * @global WP_Object_Cache $wp_object_cache
 
225
 * @see WP_Object_Cache::add_global_groups()
 
226
 * @global WP_Object_Cache $wp_object_cache Object cache global instance.
206
227
 *
207
 
 * @param string|array $groups A group or an array of groups to add
 
228
 * @param string|array $groups A group or an array of groups to add.
208
229
 */
209
230
function wp_cache_add_global_groups( $groups ) {
210
231
        global $wp_object_cache;
217
238
 *
218
239
 * @since 2.6.0
219
240
 *
220
 
 * @param string|array $groups A group or an array of groups to add
 
241
 * @param string|array $groups A group or an array of groups to add.
221
242
 */
222
243
function wp_cache_add_non_persistent_groups( $groups ) {
223
244
        // Default cache doesn't persist so nothing to do here.
224
245
}
225
246
 
226
247
/**
227
 
 * Reset internal cache keys and structures. If the cache backend uses global
228
 
 * blog or site IDs as part of its cache keys, this function instructs the
229
 
 * backend to reset those keys and perform any cleanup since blog or site IDs
230
 
 * have changed since cache init.
 
248
 * Reset internal cache keys and structures.
 
249
 *
 
250
 * If the cache backend uses global blog or site IDs as part of its cache keys,
 
251
 * this function instructs the backend to reset those keys and perform any cleanup
 
252
 * since blog or site IDs have changed since cache init.
231
253
 *
232
254
 * This function is deprecated. Use wp_cache_switch_to_blog() instead of this
233
255
 * function when preparing the cache for a blog switch. For clearing the cache
236
258
 * high.
237
259
 *
238
260
 * @since 2.6.0
239
 
 * @deprecated 3.5.0
 
261
 * @deprecated 3.5.0 WP_Object_Cache::reset()
 
262
 * @see WP_Object_Cache::reset()
240
263
 *
241
 
 * @global WP_Object_Cache $wp_object_cache
 
264
 * @global WP_Object_Cache $wp_object_cache Object cache global instance.
242
265
 */
243
266
function wp_cache_reset() {
244
267
        _deprecated_function( __FUNCTION__, '3.5' );
249
272
}
250
273
 
251
274
/**
252
 
 * WordPress Object Cache
 
275
 * Core class that implements an object cache.
253
276
 *
254
277
 * The WordPress Object Cache is used to save on trips to the database. The
255
278
 * Object Cache stores all of the cache data to memory and makes the cache
267
290
class WP_Object_Cache {
268
291
 
269
292
        /**
270
 
         * Holds the cached objects
 
293
         * Holds the cached objects.
271
294
         *
 
295
         * @since 2.0.0
 
296
         * @access private
272
297
         * @var array
273
 
         * @access private
274
 
         * @since 2.0.0
275
298
         */
276
299
        private $cache = array();
277
300
 
285
308
        private $cache_hits = 0;
286
309
 
287
310
        /**
288
 
         * Amount of times the cache did not have the request in cache
 
311
         * Amount of times the cache did not have the request in cache.
289
312
         *
 
313
         * @since 2.0.0
 
314
         * @access public
290
315
         * @var int
291
 
         * @access public
292
 
         * @since 2.0.0
293
316
         */
294
317
        public $cache_misses = 0;
295
318
 
296
319
        /**
297
 
         * List of global groups
 
320
         * List of global cache groups.
298
321
         *
 
322
         * @since 3.0.0
 
323
         * @access protected
299
324
         * @var array
300
 
         * @access protected
301
 
         * @since 3.0.0
302
325
         */
303
326
        protected $global_groups = array();
304
327
 
305
328
        /**
306
329
         * The blog prefix to prepend to keys in non-global groups.
307
330
         *
 
331
         * @since 3.5.0
 
332
         * @access private
308
333
         * @var int
309
 
         * @access private
310
 
         * @since 3.5.0
311
334
         */
312
335
        private $blog_prefix;
313
336
 
314
337
        /**
315
 
         * Holds the value of `is_multisite()`
 
338
         * Holds the value of is_multisite().
316
339
         *
 
340
         * @since 3.5.0
 
341
         * @access private
317
342
         * @var bool
318
 
         * @access private
319
 
         * @since 3.5.0
320
343
         */
321
344
        private $multisite;
322
345
 
323
346
        /**
324
 
         * Make private properties readable for backwards compatibility.
 
347
         * Makes private properties readable for backwards compatibility.
325
348
         *
326
349
         * @since 4.0.0
327
350
         * @access public
334
357
        }
335
358
 
336
359
        /**
337
 
         * Make private properties settable for backwards compatibility.
 
360
         * Makes private properties settable for backwards compatibility.
338
361
         *
339
362
         * @since 4.0.0
340
363
         * @access public
348
371
        }
349
372
 
350
373
        /**
351
 
         * Make private properties checkable for backwards compatibility.
 
374
         * Makes private properties checkable for backwards compatibility.
352
375
         *
353
376
         * @since 4.0.0
354
377
         * @access public
361
384
        }
362
385
 
363
386
        /**
364
 
         * Make private properties un-settable for backwards compatibility.
 
387
         * Makes private properties un-settable for backwards compatibility.
365
388
         *
366
389
         * @since 4.0.0
367
390
         * @access public
375
398
        /**
376
399
         * Adds data to the cache if it doesn't already exist.
377
400
         *
378
 
         * @uses WP_Object_Cache::_exists Checks to see if the cache already has data.
379
 
         * @uses WP_Object_Cache::set Sets the data after the checking the cache
380
 
         *              contents existence.
381
 
         *
382
401
         * @since 2.0.0
383
 
         *
384
 
         * @param int|string $key What to call the contents in the cache
385
 
         * @param mixed $data The contents to store in the cache
386
 
         * @param string $group Where to group the cache contents
387
 
         * @param int $expire When to expire the cache contents
 
402
         * @access public
 
403
         *
 
404
         * @uses WP_Object_Cache::_exists() Checks to see if the cache already has data.
 
405
         * @uses WP_Object_Cache::set()     Sets the data after the checking the cache
 
406
         *                                          contents existence.
 
407
         *
 
408
         * @param int|string $key    What to call the contents in the cache.
 
409
         * @param mixed      $data   The contents to store in the cache.
 
410
         * @param string     $group  Optional. Where to group the cache contents. Default 'default'.
 
411
         * @param int        $expire Optional. When to expire the cache contents. Default 0 (no expiration).
388
412
         * @return bool False if cache key and group already exist, true on success
389
413
         */
390
414
        public function add( $key, $data, $group = 'default', $expire = 0 ) {
405
429
        }
406
430
 
407
431
        /**
408
 
         * Sets the list of global groups.
 
432
         * Sets the list of global cache groups.
409
433
         *
410
434
         * @since 3.0.0
 
435
         * @access public
411
436
         *
412
437
         * @param array $groups List of groups that are global.
413
438
         */
419
444
        }
420
445
 
421
446
        /**
422
 
         * Decrement numeric cache item's value
 
447
         * Decrements numeric cache item's value.
423
448
         *
424
449
         * @since 3.3.0
 
450
         * @access public
425
451
         *
426
 
         * @param int|string $key The cache key to increment
427
 
         * @param int $offset The amount by which to decrement the item's value. Default is 1.
428
 
         * @param string $group The group the key is in.
 
452
         * @param int|string $key    The cache key to decrement.
 
453
         * @param int        $offset Optional. The amount by which to decrement the item's value. Default 1.
 
454
         * @param string     $group  Optional. The group the key is in. Default 'default'.
429
455
         * @return false|int False on failure, the item's new value on success.
430
456
         */
431
457
        public function decr( $key, $offset = 1, $group = 'default' ) {
452
478
        }
453
479
 
454
480
        /**
455
 
         * Remove the contents of the cache key in the group
 
481
         * Removes the contents of the cache key in the group.
456
482
         *
457
483
         * If the cache key does not exist in the group, then nothing will happen.
458
484
         *
459
485
         * @since 2.0.0
460
 
         *
461
 
         * @param int|string $key What the contents in the cache are called
462
 
         * @param string $group Where the cache contents are grouped
463
 
         * @param bool $deprecated Deprecated.
464
 
         *
465
 
         * @return bool False if the contents weren't deleted and true on success
 
486
         * @access public
 
487
         *
 
488
         * @param int|string $key        What the contents in the cache are called.
 
489
         * @param string     $group      Optional. Where the cache contents are grouped. Default 'default'.
 
490
         * @param bool       $deprecated Optional. Unused. Default false.
 
491
         * @return bool False if the contents weren't deleted and true on success.
466
492
         */
467
493
        public function delete( $key, $group = 'default', $deprecated = false ) {
468
494
                if ( empty( $group ) )
479
505
        }
480
506
 
481
507
        /**
482
 
         * Clears the object cache of all data
 
508
         * Clears the object cache of all data.
483
509
         *
484
510
         * @since 2.0.0
 
511
         * @access public
485
512
         *
486
 
         * @return true Always returns true
 
513
         * @return true Always returns true.
487
514
         */
488
515
        public function flush() {
489
516
                $this->cache = array();
492
519
        }
493
520
 
494
521
        /**
495
 
         * Retrieves the cache contents, if it exists
 
522
         * Retrieves the cache contents, if it exists.
496
523
         *
497
524
         * The contents will be first attempted to be retrieved by searching by the
498
525
         * key in the cache group. If the cache is hit (success) then the contents
501
528
         * On failure, the number of cache misses will be incremented.
502
529
         *
503
530
         * @since 2.0.0
 
531
         * @access public
504
532
         *
505
 
         * @param int|string $key What the contents in the cache are called
506
 
         * @param string $group Where the cache contents are grouped
507
 
         * @param string $force Whether to force a refetch rather than relying on the local cache (default is false)
508
 
         * @return false|mixed False on failure to retrieve contents or the cache
509
 
         *                             contents on success
 
533
         * @param int|string $key    What the contents in the cache are called.
 
534
         * @param string     $group  Optional. Where the cache contents are grouped. Default 'default'.
 
535
         * @param string     $force  Optional. Unused. Whether to force a refetch rather than relying on the local
 
536
         *                           cache. Default false.
 
537
         * @param bool       &$found Optional. Whether the key was found in the cache. Disambiguates a return of
 
538
         *                           false, a storable value. Passed by reference. Default null.
 
539
         * @return false|mixed False on failure to retrieve contents or the cache contents on success.
510
540
         */
511
541
        public function get( $key, $group = 'default', $force = false, &$found = null ) {
512
542
                if ( empty( $group ) )
530
560
        }
531
561
 
532
562
        /**
533
 
         * Increment numeric cache item's value
 
563
         * Increments numeric cache item's value.
534
564
         *
535
565
         * @since 3.3.0
 
566
         * @access public
536
567
         *
537
 
         * @param int|string $key The cache key to increment
538
 
         * @param int $offset The amount by which to increment the item's value. Default is 1.
539
 
         * @param string $group The group the key is in.
 
568
         * @param int|string $key    The cache key to increment
 
569
         * @param int        $offset Optional. The amount by which to increment the item's value. Default 1.
 
570
         * @param string     $group  Optional. The group the key is in. Default 'default'.
540
571
         * @return false|int False on failure, the item's new value on success.
541
572
         */
542
573
        public function incr( $key, $offset = 1, $group = 'default' ) {
563
594
        }
564
595
 
565
596
        /**
566
 
         * Replace the contents in the cache, if contents already exist
 
597
         * Replaces the contents in the cache, if contents already exist.
567
598
         *
568
599
         * @since 2.0.0
 
600
         * @access public
 
601
         *
569
602
         * @see WP_Object_Cache::set()
570
603
         *
571
 
         * @param int|string $key What to call the contents in the cache
572
 
         * @param mixed $data The contents to store in the cache
573
 
         * @param string $group Where to group the cache contents
574
 
         * @param int $expire When to expire the cache contents
575
 
         * @return bool False if not exists, true if contents were replaced
 
604
         * @param int|string $key    What to call the contents in the cache.
 
605
         * @param mixed      $data   The contents to store in the cache.
 
606
         * @param string     $group  Optional. Where to group the cache contents. Default 'default'.
 
607
         * @param int        $expire Optional. When to expire the cache contents. Default 0 (no expiration).
 
608
         * @return bool False if not exists, true if contents were replaced.
576
609
         */
577
610
        public function replace( $key, $data, $group = 'default', $expire = 0 ) {
578
611
                if ( empty( $group ) )
589
622
        }
590
623
 
591
624
        /**
592
 
         * Reset keys
 
625
         * Resets cache keys.
593
626
         *
594
627
         * @since 3.0.0
595
 
         * @deprecated 3.5.0
 
628
         * @access public
 
629
         *
 
630
         * @deprecated 3.5.0 Use switch_to_blog()
 
631
         * @see switch_to_blog()
596
632
         */
597
633
        public function reset() {
598
634
                _deprecated_function( __FUNCTION__, '3.5', 'switch_to_blog()' );
605
641
        }
606
642
 
607
643
        /**
608
 
         * Sets the data contents into the cache
 
644
         * Sets the data contents into the cache.
609
645
         *
610
646
         * The cache contents is grouped by the $group parameter followed by the
611
647
         * $key. This allows for duplicate ids in unique groups. Therefore, naming of
617
653
         * more for cache plugins which use files.
618
654
         *
619
655
         * @since 2.0.0
 
656
         * @access public
620
657
         *
621
 
         * @param int|string $key What to call the contents in the cache
622
 
         * @param mixed $data The contents to store in the cache
623
 
         * @param string $group Where to group the cache contents
624
 
         * @param int $expire Not Used
625
 
         * @return true Always returns true
 
658
         * @param int|string $key    What to call the contents in the cache.
 
659
         * @param mixed      $data   The contents to store in the cache.
 
660
         * @param string     $group  Optional. Where to group the cache contents. Default 'default'.
 
661
         * @param int        $expire Not Used.
 
662
         * @return true Always returns true.
626
663
         */
627
664
        public function set( $key, $data, $group = 'default', $expire = 0 ) {
628
665
                if ( empty( $group ) )
645
682
         * key and the data.
646
683
         *
647
684
         * @since 2.0.0
 
685
         * @access public
648
686
         */
649
687
        public function stats() {
650
688
                echo "<p>";
653
691
                echo "</p>";
654
692
                echo '<ul>';
655
693
                foreach ($this->cache as $group => $cache) {
656
 
                        echo "<li><strong>Group:</strong> $group - ( " . number_format( strlen( serialize( $cache ) ) / 1024, 2 ) . 'k )</li>';
 
694
                        echo "<li><strong>Group:</strong> $group - ( " . number_format( strlen( serialize( $cache ) ) / KB_IN_BYTES, 2 ) . 'k )</li>';
657
695
                }
658
696
                echo '</ul>';
659
697
        }
660
698
 
661
699
        /**
662
 
         * Switch the interal blog id.
 
700
         * Switches the interal blog ID.
663
701
         *
664
 
         * This changes the blog id used to create keys in blog specific groups.
 
702
         * This changes the blog ID used to create keys in blog specific groups.
665
703
         *
666
704
         * @since 3.5.0
 
705
         * @access public
667
706
         *
668
 
         * @param int $blog_id Blog ID
 
707
         * @param int $blog_id Blog ID.
669
708
         */
670
709
        public function switch_to_blog( $blog_id ) {
671
710
                $blog_id = (int) $blog_id;
673
712
        }
674
713
 
675
714
        /**
676
 
         * Utility function to determine whether a key exists in the cache.
 
715
         * Serves as a utility function to determine whether a key exists in the cache.
677
716
         *
678
717
         * @since 3.4.0
 
718
         * @access protected
679
719
         *
680
 
         * @access protected
681
 
         * @param string $key
682
 
         * @param string $group
683
 
         * @return bool
 
720
         * @param int|string $key   Cache key to check for existence.
 
721
         * @param string     $group Cache group for the key existence check.
 
722
         * @return bool Whether the key exists in the cache for the given group.
684
723
         */
685
724
        protected function _exists( $key, $group ) {
686
725
                return isset( $this->cache[ $group ] ) && ( isset( $this->cache[ $group ][ $key ] ) || array_key_exists( $key, $this->cache[ $group ] ) );
687
726
        }
688
727
 
689
728
        /**
690
 
         * Sets up object properties; PHP 5 style constructor
 
729
         * Sets up object properties; PHP 5 style constructor.
691
730
         *
692
731
         * @since 2.0.8
693
732
         *
694
 
     * @global int $blog_id
 
733
     * @global int $blog_id Global blog ID.
695
734
         */
696
735
        public function __construct() {
697
736
                global $blog_id;
708
747
        }
709
748
 
710
749
        /**
711
 
         * Will save the object cache before object is completely destroyed.
 
750
         * Saves the object cache before object is completely destroyed.
712
751
         *
713
752
         * Called upon object destruction, which should be when PHP ends.
714
753
         *
715
 
         * @since  2.0.8
 
754
         * @since 2.0.8
716
755
         *
717
 
         * @return true True value. Won't be used by PHP
 
756
         * @return true Always returns true.
718
757
         */
719
758
        public function __destruct() {
720
759
                return true;