2005-11-07 16:56:03 -05:00
|
|
|
<?php
|
2008-01-02 23:35:47 -05:00
|
|
|
/**
|
|
|
|
* Object Cache API
|
|
|
|
*
|
2015-04-12 17:29:32 -04:00
|
|
|
* @link https://codex.wordpress.org/Function_Reference/WP_Cache
|
2008-05-25 11:45:05 -04:00
|
|
|
*
|
2008-01-02 23:35:47 -05:00
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Cache
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2011-09-03 12:02:41 -04:00
|
|
|
* Adds data to the cache, if the cache key doesn't already exist.
|
2008-01-02 23:35:47 -05:00
|
|
|
*
|
2008-08-27 02:45:13 -04:00
|
|
|
* @since 2.0.0
|
2015-05-22 00:24:26 -04:00
|
|
|
*
|
2015-09-16 05:40:25 -04:00
|
|
|
* @see WP_Object_Cache::add()
|
|
|
|
* @global WP_Object_Cache $wp_object_cache Object cache global instance.
|
|
|
|
*
|
|
|
|
* @param int|string $key The cache key to use for retrieval later.
|
|
|
|
* @param mixed $data The data to add to the cache.
|
|
|
|
* @param string $group Optional. The group to add the cache to. Enables the same key
|
|
|
|
* to be used across groups. Default empty.
|
|
|
|
* @param int $expire Optional. When the cache data should expire, in seconds.
|
|
|
|
* Default 0 (no expiration).
|
2015-09-10 14:24:24 -04:00
|
|
|
* @return bool False if cache key and group already exist, true on success.
|
2008-01-02 23:35:47 -05:00
|
|
|
*/
|
2013-09-16 13:43:09 -04:00
|
|
|
function wp_cache_add( $key, $data, $group = '', $expire = 0 ) {
|
2005-11-07 16:56:03 -05:00
|
|
|
global $wp_object_cache;
|
|
|
|
|
2013-09-16 13:43:09 -04:00
|
|
|
return $wp_object_cache->add( $key, $data, $group, (int) $expire );
|
2005-11-07 16:56:03 -05:00
|
|
|
}
|
|
|
|
|
2008-01-02 23:35:47 -05:00
|
|
|
/**
|
2008-05-25 11:45:05 -04:00
|
|
|
* Closes the cache.
|
2008-01-02 23:35:47 -05:00
|
|
|
*
|
2008-05-25 11:45:05 -04:00
|
|
|
* This function has ceased to do anything since WordPress 2.5. The
|
2015-09-16 05:40:25 -04:00
|
|
|
* functionality was removed along with the rest of the persistent cache.
|
|
|
|
*
|
|
|
|
* This does not mean that plugins can't implement this function when they need
|
|
|
|
* to make sure that the cache is cleaned up after WordPress no longer needs it.
|
2008-01-02 23:35:47 -05:00
|
|
|
*
|
2008-08-27 02:45:13 -04:00
|
|
|
* @since 2.0.0
|
2008-01-02 23:35:47 -05:00
|
|
|
*
|
2015-09-16 05:40:25 -04:00
|
|
|
* @return true Always returns true.
|
2008-01-02 23:35:47 -05:00
|
|
|
*/
|
2005-11-07 16:56:03 -05:00
|
|
|
function wp_cache_close() {
|
2008-01-02 18:03:25 -05:00
|
|
|
return true;
|
2005-11-07 16:56:03 -05:00
|
|
|
}
|
|
|
|
|
2011-08-22 13:39:44 -04:00
|
|
|
/**
|
2015-09-16 05:40:25 -04:00
|
|
|
* Decrements numeric cache item's value.
|
2011-08-22 13:39:44 -04:00
|
|
|
*
|
|
|
|
* @since 3.3.0
|
2015-05-22 00:24:26 -04:00
|
|
|
*
|
2015-09-16 05:40:25 -04:00
|
|
|
* @see WP_Object_Cache::decr()
|
|
|
|
* @global WP_Object_Cache $wp_object_cache Object cache global instance.
|
2011-08-22 13:39:44 -04:00
|
|
|
*
|
2015-09-16 05:40:25 -04:00
|
|
|
* @param int|string $key The cache key to decrement.
|
|
|
|
* @param int $offset Optional. The amount by which to decrement the item's value. Default 1.
|
|
|
|
* @param string $group Optional. The group the key is in. Default empty.
|
2011-08-22 13:39:44 -04:00
|
|
|
* @return false|int False on failure, the item's new value on success.
|
|
|
|
*/
|
2011-09-06 17:13:11 -04:00
|
|
|
function wp_cache_decr( $key, $offset = 1, $group = '' ) {
|
2011-08-22 13:39:44 -04:00
|
|
|
global $wp_object_cache;
|
|
|
|
|
2011-09-06 17:13:11 -04:00
|
|
|
return $wp_object_cache->decr( $key, $offset, $group );
|
2011-08-22 13:39:44 -04:00
|
|
|
}
|
|
|
|
|
2008-01-02 23:35:47 -05:00
|
|
|
/**
|
2011-09-08 13:19:09 -04:00
|
|
|
* Removes the cache contents matching key and group.
|
2008-01-02 23:35:47 -05:00
|
|
|
*
|
2008-08-27 02:45:13 -04:00
|
|
|
* @since 2.0.0
|
2015-05-22 00:24:26 -04:00
|
|
|
*
|
2015-09-16 05:40:25 -04:00
|
|
|
* @see WP_Object_Cache::delete()
|
|
|
|
* @global WP_Object_Cache $wp_object_cache Object cache global instance.
|
2008-01-02 23:35:47 -05:00
|
|
|
*
|
2015-09-16 05:40:25 -04:00
|
|
|
* @param int|string $key What the contents in the cache are called.
|
|
|
|
* @param string $group Optional. Where the cache contents are grouped. Default empty.
|
2015-09-10 14:24:24 -04:00
|
|
|
* @return bool True on successful removal, false on failure.
|
2008-01-02 23:35:47 -05:00
|
|
|
*/
|
2015-09-16 05:40:25 -04:00
|
|
|
function wp_cache_delete( $key, $group = '' ) {
|
2005-11-07 16:56:03 -05:00
|
|
|
global $wp_object_cache;
|
|
|
|
|
2011-09-06 17:13:11 -04:00
|
|
|
return $wp_object_cache->delete($key, $group);
|
2005-11-07 16:56:03 -05:00
|
|
|
}
|
|
|
|
|
2008-01-02 23:35:47 -05:00
|
|
|
/**
|
2008-05-25 11:45:05 -04:00
|
|
|
* Removes all cache items.
|
2008-01-02 23:35:47 -05:00
|
|
|
*
|
2008-08-27 02:45:13 -04:00
|
|
|
* @since 2.0.0
|
2015-05-22 00:24:26 -04:00
|
|
|
*
|
2015-09-16 05:40:25 -04:00
|
|
|
* @see WP_Object_Cache::flush()
|
|
|
|
* @global WP_Object_Cache $wp_object_cache Object cache global instance.
|
2008-01-02 23:35:47 -05:00
|
|
|
*
|
2013-01-22 15:44:30 -05:00
|
|
|
* @return bool False on failure, true on success
|
2008-01-02 23:35:47 -05:00
|
|
|
*/
|
2005-11-07 16:56:03 -05:00
|
|
|
function wp_cache_flush() {
|
|
|
|
global $wp_object_cache;
|
2005-11-14 17:32:03 -05:00
|
|
|
|
2005-11-14 17:10:28 -05:00
|
|
|
return $wp_object_cache->flush();
|
2005-11-07 16:56:03 -05:00
|
|
|
}
|
|
|
|
|
2008-01-02 23:35:47 -05:00
|
|
|
/**
|
2011-09-08 13:19:09 -04:00
|
|
|
* Retrieves the cache contents from the cache by key and group.
|
2008-01-02 23:35:47 -05:00
|
|
|
*
|
2008-08-27 02:45:13 -04:00
|
|
|
* @since 2.0.0
|
2015-05-22 00:24:26 -04:00
|
|
|
*
|
2015-09-16 05:40:25 -04:00
|
|
|
* @see WP_Object_Cache::get()
|
|
|
|
* @global WP_Object_Cache $wp_object_cache Object cache global instance.
|
2008-01-02 23:35:47 -05:00
|
|
|
*
|
2015-09-16 05:40:25 -04:00
|
|
|
* @param int|string $key The key under which the cache contents are stored.
|
|
|
|
* @param string $group Optional. Where the cache contents are grouped. Default empty.
|
|
|
|
* @param bool $force Optional. Whether to force an update of the local cache from the persistent
|
|
|
|
* cache. Default false.
|
2015-12-23 01:31:27 -05:00
|
|
|
* @param bool $found Optional. Whether the key was found in the cache. Disambiguates a return of false,
|
2015-09-16 05:40:25 -04:00
|
|
|
* a storable value. Passed by reference. Default null.
|
2008-05-25 11:45:05 -04:00
|
|
|
* @return bool|mixed False on failure to retrieve contents or the cache
|
2015-05-21 16:22:24 -04:00
|
|
|
* contents on success
|
2008-01-02 23:35:47 -05:00
|
|
|
*/
|
2012-03-02 16:10:37 -05:00
|
|
|
function wp_cache_get( $key, $group = '', $force = false, &$found = null ) {
|
2005-11-07 16:56:03 -05:00
|
|
|
global $wp_object_cache;
|
|
|
|
|
2012-03-02 16:10:37 -05:00
|
|
|
return $wp_object_cache->get( $key, $group, $force, $found );
|
2005-11-07 16:56:03 -05:00
|
|
|
}
|
|
|
|
|
2011-08-22 13:39:44 -04:00
|
|
|
/**
|
|
|
|
* Increment numeric cache item's value
|
|
|
|
*
|
|
|
|
* @since 3.3.0
|
2015-05-22 00:24:26 -04:00
|
|
|
*
|
2015-09-16 05:40:25 -04:00
|
|
|
* @see WP_Object_Cache::incr()
|
|
|
|
* @global WP_Object_Cache $wp_object_cache Object cache global instance.
|
2011-08-22 13:39:44 -04:00
|
|
|
*
|
2015-09-16 05:40:25 -04:00
|
|
|
* @param int|string $key The key for the cache contents that should be incremented.
|
|
|
|
* @param int $offset Optional. The amount by which to increment the item's value. Default 1.
|
|
|
|
* @param string $group Optional. The group the key is in. Default empty.
|
2011-08-22 13:39:44 -04:00
|
|
|
* @return false|int False on failure, the item's new value on success.
|
|
|
|
*/
|
2011-09-06 17:13:11 -04:00
|
|
|
function wp_cache_incr( $key, $offset = 1, $group = '' ) {
|
2011-08-22 13:39:44 -04:00
|
|
|
global $wp_object_cache;
|
|
|
|
|
2011-09-06 17:13:11 -04:00
|
|
|
return $wp_object_cache->incr( $key, $offset, $group );
|
2011-08-22 13:39:44 -04:00
|
|
|
}
|
|
|
|
|
2008-01-02 23:35:47 -05:00
|
|
|
/**
|
2008-05-25 11:45:05 -04:00
|
|
|
* Sets up Object Cache Global and assigns it.
|
2008-01-02 23:35:47 -05:00
|
|
|
*
|
2008-08-27 02:45:13 -04:00
|
|
|
* @since 2.0.0
|
2015-05-22 00:24:26 -04:00
|
|
|
*
|
|
|
|
* @global WP_Object_Cache $wp_object_cache
|
2008-01-02 23:35:47 -05:00
|
|
|
*/
|
2005-11-07 16:56:03 -05:00
|
|
|
function wp_cache_init() {
|
2011-10-18 16:20:59 -04:00
|
|
|
$GLOBALS['wp_object_cache'] = new WP_Object_Cache();
|
2005-11-07 16:56:03 -05:00
|
|
|
}
|
|
|
|
|
2008-01-02 23:35:47 -05:00
|
|
|
/**
|
2008-05-25 11:45:05 -04:00
|
|
|
* Replaces the contents of the cache with new data.
|
2008-01-02 23:35:47 -05:00
|
|
|
*
|
2008-08-27 02:45:13 -04:00
|
|
|
* @since 2.0.0
|
2015-05-22 00:24:26 -04:00
|
|
|
*
|
2015-09-16 05:40:25 -04:00
|
|
|
* @see WP_Object_Cache::replace()
|
|
|
|
* @global WP_Object_Cache $wp_object_cache Object cache global instance.
|
2008-01-02 23:35:47 -05:00
|
|
|
*
|
2015-09-16 05:40:25 -04:00
|
|
|
* @param int|string $key The key for the cache data that should be replaced.
|
|
|
|
* @param mixed $data The new data to store in the cache.
|
|
|
|
* @param string $group Optional. The group for the cache data that should be replaced.
|
|
|
|
* Default empty.
|
|
|
|
* @param int $expire Optional. When to expire the cache contents, in seconds.
|
|
|
|
* Default 0 (no expiration).
|
2015-09-10 14:24:24 -04:00
|
|
|
* @return bool False if original value does not exist, true if contents were replaced
|
2008-01-02 23:35:47 -05:00
|
|
|
*/
|
2013-09-16 13:43:09 -04:00
|
|
|
function wp_cache_replace( $key, $data, $group = '', $expire = 0 ) {
|
2005-11-07 16:56:03 -05:00
|
|
|
global $wp_object_cache;
|
|
|
|
|
2013-09-16 13:43:09 -04:00
|
|
|
return $wp_object_cache->replace( $key, $data, $group, (int) $expire );
|
2005-11-07 16:56:03 -05:00
|
|
|
}
|
|
|
|
|
2008-01-02 23:35:47 -05:00
|
|
|
/**
|
2008-05-25 11:45:05 -04:00
|
|
|
* Saves the data to the cache.
|
2008-01-02 23:35:47 -05:00
|
|
|
*
|
2015-09-10 14:24:24 -04:00
|
|
|
* Differs from wp_cache_add() and wp_cache_replace() in that it will always write data.
|
|
|
|
*
|
2013-12-24 13:57:12 -05:00
|
|
|
* @since 2.0.0
|
|
|
|
*
|
2015-09-16 05:40:25 -04:00
|
|
|
* @see WP_Object_Cache::set()
|
|
|
|
* @global WP_Object_Cache $wp_object_cache Object cache global instance.
|
2008-01-02 23:35:47 -05:00
|
|
|
*
|
2015-09-16 05:40:25 -04:00
|
|
|
* @param int|string $key The cache key to use for retrieval later.
|
|
|
|
* @param mixed $data The contents to store in the cache.
|
|
|
|
* @param string $group Optional. Where to group the cache contents. Enables the same key
|
|
|
|
* to be used across groups. Default empty.
|
|
|
|
* @param int $expire Optional. When to expire the cache contents, in seconds.
|
|
|
|
* Default 0 (no expiration).
|
2013-01-22 15:44:30 -05:00
|
|
|
* @return bool False on failure, true on success
|
2008-01-02 23:35:47 -05:00
|
|
|
*/
|
2013-09-16 13:43:09 -04:00
|
|
|
function wp_cache_set( $key, $data, $group = '', $expire = 0 ) {
|
2005-11-07 16:56:03 -05:00
|
|
|
global $wp_object_cache;
|
|
|
|
|
2013-09-16 13:43:09 -04:00
|
|
|
return $wp_object_cache->set( $key, $data, $group, (int) $expire );
|
2005-11-07 16:56:03 -05:00
|
|
|
}
|
|
|
|
|
2012-08-02 14:31:14 -04:00
|
|
|
/**
|
2016-04-16 08:37:30 -04:00
|
|
|
* Switches the internal blog ID.
|
2012-08-02 14:31:14 -04:00
|
|
|
*
|
|
|
|
* This changes the blog id used to create keys in blog specific groups.
|
|
|
|
*
|
2012-09-30 10:02:59 -04:00
|
|
|
* @since 3.5.0
|
|
|
|
*
|
2015-09-16 05:40:25 -04:00
|
|
|
* @see WP_Object_Cache::switch_to_blog()
|
|
|
|
* @global WP_Object_Cache $wp_object_cache Object cache global instance.
|
2015-05-22 00:24:26 -04:00
|
|
|
*
|
2016-01-27 22:35:27 -05:00
|
|
|
* @param int $blog_id Site ID.
|
2012-08-02 14:31:14 -04:00
|
|
|
*/
|
|
|
|
function wp_cache_switch_to_blog( $blog_id ) {
|
|
|
|
global $wp_object_cache;
|
|
|
|
|
2015-05-21 16:22:24 -04:00
|
|
|
$wp_object_cache->switch_to_blog( $blog_id );
|
2012-08-02 14:31:14 -04:00
|
|
|
}
|
|
|
|
|
2008-05-22 13:28:54 -04:00
|
|
|
/**
|
2008-05-25 11:45:05 -04:00
|
|
|
* Adds a group or set of groups to the list of global groups.
|
2008-05-22 13:28:54 -04:00
|
|
|
*
|
2008-08-27 02:45:13 -04:00
|
|
|
* @since 2.6.0
|
2008-05-22 13:28:54 -04:00
|
|
|
*
|
2015-09-16 05:40:25 -04:00
|
|
|
* @see WP_Object_Cache::add_global_groups()
|
|
|
|
* @global WP_Object_Cache $wp_object_cache Object cache global instance.
|
2015-05-22 00:24:26 -04:00
|
|
|
*
|
2015-09-16 05:40:25 -04:00
|
|
|
* @param string|array $groups A group or an array of groups to add.
|
2008-05-22 13:28:54 -04:00
|
|
|
*/
|
|
|
|
function wp_cache_add_global_groups( $groups ) {
|
2010-02-12 12:06:43 -05:00
|
|
|
global $wp_object_cache;
|
|
|
|
|
2015-05-21 16:22:24 -04:00
|
|
|
$wp_object_cache->add_global_groups( $groups );
|
2008-05-22 13:28:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-05-25 11:45:05 -04:00
|
|
|
* Adds a group or set of groups to the list of non-persistent groups.
|
2008-05-22 13:28:54 -04:00
|
|
|
*
|
2008-08-27 02:45:13 -04:00
|
|
|
* @since 2.6.0
|
2008-05-22 13:28:54 -04:00
|
|
|
*
|
2015-09-16 05:40:25 -04:00
|
|
|
* @param string|array $groups A group or an array of groups to add.
|
2008-05-22 13:28:54 -04:00
|
|
|
*/
|
|
|
|
function wp_cache_add_non_persistent_groups( $groups ) {
|
|
|
|
// Default cache doesn't persist so nothing to do here.
|
|
|
|
}
|
|
|
|
|
2010-02-12 12:06:43 -05:00
|
|
|
/**
|
2015-09-16 05:40:25 -04:00
|
|
|
* Reset internal cache keys and structures.
|
|
|
|
*
|
2016-02-25 07:53:27 -05:00
|
|
|
* If the cache back end uses global blog or site IDs as part of its cache keys,
|
|
|
|
* this function instructs the back end to reset those keys and perform any cleanup
|
2015-09-16 05:40:25 -04:00
|
|
|
* since blog or site IDs have changed since cache init.
|
2012-10-04 11:32:55 -04:00
|
|
|
*
|
|
|
|
* This function is deprecated. Use wp_cache_switch_to_blog() instead of this
|
|
|
|
* function when preparing the cache for a blog switch. For clearing the cache
|
|
|
|
* during unit tests, consider using wp_cache_init(). wp_cache_init() is not
|
|
|
|
* recommended outside of unit tests as the performance penality for using it is
|
|
|
|
* high.
|
2010-02-12 12:06:43 -05:00
|
|
|
*
|
|
|
|
* @since 2.6.0
|
2015-09-16 05:40:25 -04:00
|
|
|
* @deprecated 3.5.0 WP_Object_Cache::reset()
|
|
|
|
* @see WP_Object_Cache::reset()
|
2015-05-22 00:24:26 -04:00
|
|
|
*
|
2015-09-16 05:40:25 -04:00
|
|
|
* @global WP_Object_Cache $wp_object_cache Object cache global instance.
|
2010-02-12 12:06:43 -05:00
|
|
|
*/
|
|
|
|
function wp_cache_reset() {
|
2015-09-16 05:42:24 -04:00
|
|
|
_deprecated_function( __FUNCTION__, '3.5' );
|
2012-08-02 14:31:14 -04:00
|
|
|
|
2010-02-12 12:06:43 -05:00
|
|
|
global $wp_object_cache;
|
|
|
|
|
2015-05-21 16:22:24 -04:00
|
|
|
$wp_object_cache->reset();
|
2010-02-12 12:06:43 -05:00
|
|
|
}
|
|
|
|
|
2008-01-02 23:35:47 -05:00
|
|
|
/**
|
2015-09-16 06:03:26 -04:00
|
|
|
* Core class that implements an object cache.
|
2008-01-02 23:35:47 -05:00
|
|
|
*
|
2008-05-25 11:45:05 -04:00
|
|
|
* The WordPress Object Cache is used to save on trips to the database. The
|
|
|
|
* Object Cache stores all of the cache data to memory and makes the cache
|
|
|
|
* contents available by using a key, which is used to name and later retrieve
|
|
|
|
* the cache contents.
|
2008-01-02 23:35:47 -05:00
|
|
|
*
|
2008-05-25 11:45:05 -04:00
|
|
|
* The Object Cache can be replaced by other caching mechanisms by placing files
|
|
|
|
* in the wp-content folder which is looked at in wp-settings. If that file
|
|
|
|
* exists, then this file will not be included.
|
2008-01-02 23:35:47 -05:00
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Cache
|
2013-12-24 13:57:12 -05:00
|
|
|
* @since 2.0.0
|
2008-01-02 23:35:47 -05:00
|
|
|
*/
|
2005-11-07 16:56:03 -05:00
|
|
|
class WP_Object_Cache {
|
2008-01-02 23:35:47 -05:00
|
|
|
|
|
|
|
/**
|
2015-09-16 06:03:26 -04:00
|
|
|
* Holds the cached objects.
|
2008-01-02 23:35:47 -05:00
|
|
|
*
|
2008-08-27 02:45:13 -04:00
|
|
|
* @since 2.0.0
|
2015-09-16 06:03:26 -04:00
|
|
|
* @access private
|
|
|
|
* @var array
|
2008-01-02 23:35:47 -05:00
|
|
|
*/
|
2014-05-19 02:31:15 -04:00
|
|
|
private $cache = array();
|
2008-01-02 23:35:47 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The amount of times the cache data was already stored in the cache.
|
|
|
|
*
|
2008-08-27 02:45:13 -04:00
|
|
|
* @since 2.5.0
|
2008-01-02 23:35:47 -05:00
|
|
|
* @access private
|
|
|
|
* @var int
|
|
|
|
*/
|
2014-05-19 01:16:15 -04:00
|
|
|
private $cache_hits = 0;
|
2008-01-02 23:35:47 -05:00
|
|
|
|
|
|
|
/**
|
2015-09-16 06:03:26 -04:00
|
|
|
* Amount of times the cache did not have the request in cache.
|
2008-01-02 23:35:47 -05:00
|
|
|
*
|
2008-08-27 02:45:13 -04:00
|
|
|
* @since 2.0.0
|
2015-09-16 06:03:26 -04:00
|
|
|
* @access public
|
|
|
|
* @var int
|
2008-01-02 23:35:47 -05:00
|
|
|
*/
|
2014-05-19 01:16:15 -04:00
|
|
|
public $cache_misses = 0;
|
2006-01-13 19:05:22 -05:00
|
|
|
|
2010-02-12 12:06:43 -05:00
|
|
|
/**
|
2015-09-16 06:03:26 -04:00
|
|
|
* List of global cache groups.
|
2010-02-12 12:06:43 -05:00
|
|
|
*
|
|
|
|
* @since 3.0.0
|
2015-09-16 06:03:26 -04:00
|
|
|
* @access protected
|
|
|
|
* @var array
|
2010-02-12 12:06:43 -05:00
|
|
|
*/
|
2014-05-19 01:16:15 -04:00
|
|
|
protected $global_groups = array();
|
2010-02-12 12:06:43 -05:00
|
|
|
|
2012-08-02 14:31:14 -04:00
|
|
|
/**
|
|
|
|
* The blog prefix to prepend to keys in non-global groups.
|
|
|
|
*
|
|
|
|
* @since 3.5.0
|
2015-09-16 06:03:26 -04:00
|
|
|
* @access private
|
|
|
|
* @var int
|
2012-08-02 14:31:14 -04:00
|
|
|
*/
|
2014-05-19 01:16:15 -04:00
|
|
|
private $blog_prefix;
|
|
|
|
|
2015-03-08 22:18:27 -04:00
|
|
|
/**
|
2015-09-16 06:03:26 -04:00
|
|
|
* Holds the value of is_multisite().
|
2015-03-08 22:18:27 -04:00
|
|
|
*
|
|
|
|
* @since 3.5.0
|
2015-09-16 06:03:26 -04:00
|
|
|
* @access private
|
|
|
|
* @var bool
|
2015-03-08 22:18:27 -04:00
|
|
|
*/
|
|
|
|
private $multisite;
|
|
|
|
|
2014-05-19 01:16:15 -04:00
|
|
|
/**
|
2016-05-13 14:41:31 -04:00
|
|
|
* Makes private properties readable for backward compatibility.
|
2014-05-19 01:16:15 -04:00
|
|
|
*
|
|
|
|
* @since 4.0.0
|
2014-07-13 19:46:14 -04:00
|
|
|
* @access public
|
|
|
|
*
|
|
|
|
* @param string $name Property to get.
|
|
|
|
* @return mixed Property.
|
2014-05-19 01:16:15 -04:00
|
|
|
*/
|
|
|
|
public function __get( $name ) {
|
|
|
|
return $this->$name;
|
|
|
|
}
|
2012-08-02 14:31:14 -04:00
|
|
|
|
2014-05-19 02:31:15 -04:00
|
|
|
/**
|
2016-05-13 14:41:31 -04:00
|
|
|
* Makes private properties settable for backward compatibility.
|
2014-05-19 02:31:15 -04:00
|
|
|
*
|
|
|
|
* @since 4.0.0
|
2014-07-13 19:46:14 -04:00
|
|
|
* @access public
|
|
|
|
*
|
|
|
|
* @param string $name Property to set.
|
|
|
|
* @param mixed $value Property value.
|
|
|
|
* @return mixed Newly-set property.
|
2014-05-19 02:31:15 -04:00
|
|
|
*/
|
|
|
|
public function __set( $name, $value ) {
|
|
|
|
return $this->$name = $value;
|
|
|
|
}
|
|
|
|
|
2014-05-19 02:52:14 -04:00
|
|
|
/**
|
2016-05-13 14:41:31 -04:00
|
|
|
* Makes private properties checkable for backward compatibility.
|
2014-05-19 02:52:14 -04:00
|
|
|
*
|
|
|
|
* @since 4.0.0
|
2014-07-13 19:46:14 -04:00
|
|
|
* @access public
|
|
|
|
*
|
|
|
|
* @param string $name Property to check if set.
|
|
|
|
* @return bool Whether the property is set.
|
2014-05-19 02:52:14 -04:00
|
|
|
*/
|
|
|
|
public function __isset( $name ) {
|
|
|
|
return isset( $this->$name );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-05-13 14:41:31 -04:00
|
|
|
* Makes private properties un-settable for backward compatibility.
|
2014-05-19 02:52:14 -04:00
|
|
|
*
|
|
|
|
* @since 4.0.0
|
2014-07-13 19:46:14 -04:00
|
|
|
* @access public
|
|
|
|
*
|
|
|
|
* @param string $name Property to unset.
|
2014-05-19 02:52:14 -04:00
|
|
|
*/
|
|
|
|
public function __unset( $name ) {
|
|
|
|
unset( $this->$name );
|
|
|
|
}
|
|
|
|
|
2008-01-02 23:35:47 -05:00
|
|
|
/**
|
|
|
|
* Adds data to the cache if it doesn't already exist.
|
|
|
|
*
|
2008-08-27 02:45:13 -04:00
|
|
|
* @since 2.0.0
|
2015-09-16 06:03:26 -04:00
|
|
|
* @access public
|
|
|
|
*
|
|
|
|
* @uses WP_Object_Cache::_exists() Checks to see if the cache already has data.
|
|
|
|
* @uses WP_Object_Cache::set() Sets the data after the checking the cache
|
|
|
|
* contents existence.
|
2008-01-02 23:35:47 -05:00
|
|
|
*
|
2015-09-16 06:03:26 -04:00
|
|
|
* @param int|string $key What to call the contents in the cache.
|
|
|
|
* @param mixed $data The contents to store in the cache.
|
|
|
|
* @param string $group Optional. Where to group the cache contents. Default 'default'.
|
|
|
|
* @param int $expire Optional. When to expire the cache contents. Default 0 (no expiration).
|
2011-09-08 13:19:09 -04:00
|
|
|
* @return bool False if cache key and group already exist, true on success
|
2008-01-02 23:35:47 -05:00
|
|
|
*/
|
2014-05-19 01:16:15 -04:00
|
|
|
public function add( $key, $data, $group = 'default', $expire = 0 ) {
|
2011-09-15 16:23:00 -04:00
|
|
|
if ( wp_suspend_cache_addition() )
|
|
|
|
return false;
|
|
|
|
|
2012-03-02 16:10:37 -05:00
|
|
|
if ( empty( $group ) )
|
2005-11-07 16:56:03 -05:00
|
|
|
$group = 'default';
|
|
|
|
|
2012-08-02 14:31:14 -04:00
|
|
|
$id = $key;
|
|
|
|
if ( $this->multisite && ! isset( $this->global_groups[ $group ] ) )
|
|
|
|
$id = $this->blog_prefix . $key;
|
|
|
|
|
|
|
|
if ( $this->_exists( $id, $group ) )
|
2005-11-07 16:56:03 -05:00
|
|
|
return false;
|
|
|
|
|
2013-09-16 13:43:09 -04:00
|
|
|
return $this->set( $key, $data, $group, (int) $expire );
|
2005-11-07 16:56:03 -05:00
|
|
|
}
|
|
|
|
|
2010-02-12 12:06:43 -05:00
|
|
|
/**
|
2015-09-16 06:03:26 -04:00
|
|
|
* Sets the list of global cache groups.
|
2010-02-12 12:06:43 -05:00
|
|
|
*
|
|
|
|
* @since 3.0.0
|
2015-09-16 06:03:26 -04:00
|
|
|
* @access public
|
2010-02-12 12:06:43 -05:00
|
|
|
*
|
|
|
|
* @param array $groups List of groups that are global.
|
|
|
|
*/
|
2014-05-19 01:16:15 -04:00
|
|
|
public function add_global_groups( $groups ) {
|
2010-02-12 12:06:43 -05:00
|
|
|
$groups = (array) $groups;
|
|
|
|
|
2012-08-02 14:31:14 -04:00
|
|
|
$groups = array_fill_keys( $groups, true );
|
|
|
|
$this->global_groups = array_merge( $this->global_groups, $groups );
|
2010-02-12 12:06:43 -05:00
|
|
|
}
|
|
|
|
|
2011-08-22 13:39:44 -04:00
|
|
|
/**
|
2015-09-16 06:03:26 -04:00
|
|
|
* Decrements numeric cache item's value.
|
2011-08-22 13:39:44 -04:00
|
|
|
*
|
|
|
|
* @since 3.3.0
|
2015-09-16 06:03:26 -04:00
|
|
|
* @access public
|
2011-08-22 13:39:44 -04:00
|
|
|
*
|
2015-09-16 06:03:26 -04:00
|
|
|
* @param int|string $key The cache key to decrement.
|
|
|
|
* @param int $offset Optional. The amount by which to decrement the item's value. Default 1.
|
|
|
|
* @param string $group Optional. The group the key is in. Default 'default'.
|
2011-08-22 13:39:44 -04:00
|
|
|
* @return false|int False on failure, the item's new value on success.
|
|
|
|
*/
|
2014-05-19 01:16:15 -04:00
|
|
|
public function decr( $key, $offset = 1, $group = 'default' ) {
|
2012-07-20 16:15:25 -04:00
|
|
|
if ( empty( $group ) )
|
|
|
|
$group = 'default';
|
2012-08-02 14:31:14 -04:00
|
|
|
|
|
|
|
if ( $this->multisite && ! isset( $this->global_groups[ $group ] ) )
|
|
|
|
$key = $this->blog_prefix . $key;
|
|
|
|
|
2012-03-02 16:10:37 -05:00
|
|
|
if ( ! $this->_exists( $key, $group ) )
|
2011-08-22 13:39:44 -04:00
|
|
|
return false;
|
|
|
|
|
2011-09-06 17:13:11 -04:00
|
|
|
if ( ! is_numeric( $this->cache[ $group ][ $key ] ) )
|
|
|
|
$this->cache[ $group ][ $key ] = 0;
|
2011-08-22 13:39:44 -04:00
|
|
|
|
|
|
|
$offset = (int) $offset;
|
|
|
|
|
2011-09-06 17:13:11 -04:00
|
|
|
$this->cache[ $group ][ $key ] -= $offset;
|
2011-08-22 13:39:44 -04:00
|
|
|
|
2011-09-06 17:13:11 -04:00
|
|
|
if ( $this->cache[ $group ][ $key ] < 0 )
|
|
|
|
$this->cache[ $group ][ $key ] = 0;
|
2011-08-22 13:39:44 -04:00
|
|
|
|
2011-09-06 17:13:11 -04:00
|
|
|
return $this->cache[ $group ][ $key ];
|
2011-08-22 13:39:44 -04:00
|
|
|
}
|
|
|
|
|
2008-01-02 23:35:47 -05:00
|
|
|
/**
|
2015-09-16 06:03:26 -04:00
|
|
|
* Removes the contents of the cache key in the group.
|
2008-01-02 23:35:47 -05:00
|
|
|
*
|
2014-02-01 17:25:16 -05:00
|
|
|
* If the cache key does not exist in the group, then nothing will happen.
|
2008-01-02 23:35:47 -05:00
|
|
|
*
|
2008-08-27 02:45:13 -04:00
|
|
|
* @since 2.0.0
|
2015-09-16 06:03:26 -04:00
|
|
|
* @access public
|
2008-01-02 23:35:47 -05:00
|
|
|
*
|
2015-09-16 06:03:26 -04:00
|
|
|
* @param int|string $key What the contents in the cache are called.
|
|
|
|
* @param string $group Optional. Where the cache contents are grouped. Default 'default'.
|
|
|
|
* @param bool $deprecated Optional. Unused. Default false.
|
|
|
|
* @return bool False if the contents weren't deleted and true on success.
|
2008-01-02 23:35:47 -05:00
|
|
|
*/
|
2014-05-19 01:16:15 -04:00
|
|
|
public function delete( $key, $group = 'default', $deprecated = false ) {
|
2012-03-02 16:10:37 -05:00
|
|
|
if ( empty( $group ) )
|
2005-11-07 16:56:03 -05:00
|
|
|
$group = 'default';
|
|
|
|
|
2012-08-02 14:31:14 -04:00
|
|
|
if ( $this->multisite && ! isset( $this->global_groups[ $group ] ) )
|
|
|
|
$key = $this->blog_prefix . $key;
|
|
|
|
|
2014-02-01 17:25:16 -05:00
|
|
|
if ( ! $this->_exists( $key, $group ) )
|
2005-11-07 16:56:03 -05:00
|
|
|
return false;
|
|
|
|
|
2012-03-02 16:10:37 -05:00
|
|
|
unset( $this->cache[$group][$key] );
|
2005-11-07 16:56:03 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-01-02 23:35:47 -05:00
|
|
|
/**
|
2015-09-16 06:03:26 -04:00
|
|
|
* Clears the object cache of all data.
|
2008-01-02 23:35:47 -05:00
|
|
|
*
|
2008-08-27 02:45:13 -04:00
|
|
|
* @since 2.0.0
|
2015-09-16 06:03:26 -04:00
|
|
|
* @access public
|
2008-01-02 23:35:47 -05:00
|
|
|
*
|
2015-09-16 06:03:26 -04:00
|
|
|
* @return true Always returns true.
|
2008-01-02 23:35:47 -05:00
|
|
|
*/
|
2014-05-19 01:16:15 -04:00
|
|
|
public function flush() {
|
2015-05-22 00:24:26 -04:00
|
|
|
$this->cache = array();
|
2006-01-13 19:05:22 -05:00
|
|
|
|
2005-11-14 17:32:03 -05:00
|
|
|
return true;
|
2005-11-14 17:10:28 -05:00
|
|
|
}
|
2005-11-14 17:32:03 -05:00
|
|
|
|
2008-01-02 23:35:47 -05:00
|
|
|
/**
|
2015-09-16 06:03:26 -04:00
|
|
|
* Retrieves the cache contents, if it exists.
|
2008-01-02 23:35:47 -05:00
|
|
|
*
|
2008-05-25 11:45:05 -04:00
|
|
|
* The contents will be first attempted to be retrieved by searching by the
|
2011-09-08 13:19:09 -04:00
|
|
|
* key in the cache group. If the cache is hit (success) then the contents
|
2008-05-25 11:45:05 -04:00
|
|
|
* are returned.
|
2008-01-02 23:35:47 -05:00
|
|
|
*
|
2011-09-15 16:28:06 -04:00
|
|
|
* On failure, the number of cache misses will be incremented.
|
2008-01-02 23:35:47 -05:00
|
|
|
*
|
2008-08-27 02:45:13 -04:00
|
|
|
* @since 2.0.0
|
2015-09-16 06:03:26 -04:00
|
|
|
* @access public
|
2008-01-02 23:35:47 -05:00
|
|
|
*
|
2015-09-16 06:03:26 -04:00
|
|
|
* @param int|string $key What the contents in the cache are called.
|
|
|
|
* @param string $group Optional. Where the cache contents are grouped. Default 'default'.
|
|
|
|
* @param string $force Optional. Unused. Whether to force a refetch rather than relying on the local
|
|
|
|
* cache. Default false.
|
2015-12-23 01:31:27 -05:00
|
|
|
* @param bool $found Optional. Whether the key was found in the cache. Disambiguates a return of
|
2015-09-16 06:03:26 -04:00
|
|
|
* false, a storable value. Passed by reference. Default null.
|
|
|
|
* @return false|mixed False on failure to retrieve contents or the cache contents on success.
|
2008-01-02 23:35:47 -05:00
|
|
|
*/
|
2014-05-19 01:16:15 -04:00
|
|
|
public function get( $key, $group = 'default', $force = false, &$found = null ) {
|
2012-03-02 16:10:37 -05:00
|
|
|
if ( empty( $group ) )
|
2005-11-07 16:56:03 -05:00
|
|
|
$group = 'default';
|
|
|
|
|
2012-08-02 14:31:14 -04:00
|
|
|
if ( $this->multisite && ! isset( $this->global_groups[ $group ] ) )
|
|
|
|
$key = $this->blog_prefix . $key;
|
|
|
|
|
2012-03-02 16:10:37 -05:00
|
|
|
if ( $this->_exists( $key, $group ) ) {
|
|
|
|
$found = true;
|
2008-01-02 17:13:16 -05:00
|
|
|
$this->cache_hits += 1;
|
2011-09-06 17:13:11 -04:00
|
|
|
if ( is_object($this->cache[$group][$key]) )
|
|
|
|
return clone $this->cache[$group][$key];
|
2008-11-17 16:01:12 -05:00
|
|
|
else
|
2011-09-06 17:13:11 -04:00
|
|
|
return $this->cache[$group][$key];
|
2005-11-07 16:56:03 -05:00
|
|
|
}
|
|
|
|
|
2012-03-02 16:10:37 -05:00
|
|
|
$found = false;
|
2008-01-02 17:13:16 -05:00
|
|
|
$this->cache_misses += 1;
|
|
|
|
return false;
|
2006-01-13 19:05:22 -05:00
|
|
|
}
|
|
|
|
|
2011-08-22 13:39:44 -04:00
|
|
|
/**
|
2015-09-16 06:03:26 -04:00
|
|
|
* Increments numeric cache item's value.
|
2011-08-22 13:39:44 -04:00
|
|
|
*
|
|
|
|
* @since 3.3.0
|
2015-09-16 06:03:26 -04:00
|
|
|
* @access public
|
2011-08-22 13:39:44 -04:00
|
|
|
*
|
2015-09-16 06:03:26 -04:00
|
|
|
* @param int|string $key The cache key to increment
|
|
|
|
* @param int $offset Optional. The amount by which to increment the item's value. Default 1.
|
|
|
|
* @param string $group Optional. The group the key is in. Default 'default'.
|
2011-08-22 13:39:44 -04:00
|
|
|
* @return false|int False on failure, the item's new value on success.
|
|
|
|
*/
|
2014-05-19 01:16:15 -04:00
|
|
|
public function incr( $key, $offset = 1, $group = 'default' ) {
|
2012-03-02 16:10:37 -05:00
|
|
|
if ( empty( $group ) )
|
|
|
|
$group = 'default';
|
|
|
|
|
2012-08-02 14:31:14 -04:00
|
|
|
if ( $this->multisite && ! isset( $this->global_groups[ $group ] ) )
|
|
|
|
$key = $this->blog_prefix . $key;
|
|
|
|
|
2012-03-02 16:10:37 -05:00
|
|
|
if ( ! $this->_exists( $key, $group ) )
|
2011-08-22 13:39:44 -04:00
|
|
|
return false;
|
|
|
|
|
2011-09-06 17:13:11 -04:00
|
|
|
if ( ! is_numeric( $this->cache[ $group ][ $key ] ) )
|
|
|
|
$this->cache[ $group ][ $key ] = 0;
|
2011-08-22 13:39:44 -04:00
|
|
|
|
|
|
|
$offset = (int) $offset;
|
|
|
|
|
2011-09-06 17:13:11 -04:00
|
|
|
$this->cache[ $group ][ $key ] += $offset;
|
2011-08-22 13:39:44 -04:00
|
|
|
|
2011-09-06 17:13:11 -04:00
|
|
|
if ( $this->cache[ $group ][ $key ] < 0 )
|
|
|
|
$this->cache[ $group ][ $key ] = 0;
|
2011-08-22 13:39:44 -04:00
|
|
|
|
2011-09-06 17:13:11 -04:00
|
|
|
return $this->cache[ $group ][ $key ];
|
2011-08-22 13:39:44 -04:00
|
|
|
}
|
|
|
|
|
2008-01-02 23:35:47 -05:00
|
|
|
/**
|
2015-09-16 06:03:26 -04:00
|
|
|
* Replaces the contents in the cache, if contents already exist.
|
2008-01-02 23:35:47 -05:00
|
|
|
*
|
2008-08-27 02:45:13 -04:00
|
|
|
* @since 2.0.0
|
2015-09-16 06:03:26 -04:00
|
|
|
* @access public
|
|
|
|
*
|
2008-01-02 23:35:47 -05:00
|
|
|
* @see WP_Object_Cache::set()
|
|
|
|
*
|
2015-09-16 06:03:26 -04:00
|
|
|
* @param int|string $key What to call the contents in the cache.
|
|
|
|
* @param mixed $data The contents to store in the cache.
|
|
|
|
* @param string $group Optional. Where to group the cache contents. Default 'default'.
|
|
|
|
* @param int $expire Optional. When to expire the cache contents. Default 0 (no expiration).
|
|
|
|
* @return bool False if not exists, true if contents were replaced.
|
2008-01-02 23:35:47 -05:00
|
|
|
*/
|
2014-05-19 01:16:15 -04:00
|
|
|
public function replace( $key, $data, $group = 'default', $expire = 0 ) {
|
2012-03-02 16:10:37 -05:00
|
|
|
if ( empty( $group ) )
|
2005-11-07 16:56:03 -05:00
|
|
|
$group = 'default';
|
|
|
|
|
2012-08-02 14:31:14 -04:00
|
|
|
$id = $key;
|
|
|
|
if ( $this->multisite && ! isset( $this->global_groups[ $group ] ) )
|
|
|
|
$id = $this->blog_prefix . $key;
|
|
|
|
|
|
|
|
if ( ! $this->_exists( $id, $group ) )
|
2005-11-07 16:56:03 -05:00
|
|
|
return false;
|
|
|
|
|
2013-09-16 13:43:09 -04:00
|
|
|
return $this->set( $key, $data, $group, (int) $expire );
|
2005-11-07 16:56:03 -05:00
|
|
|
}
|
|
|
|
|
2010-02-12 12:06:43 -05:00
|
|
|
/**
|
2015-09-16 06:03:26 -04:00
|
|
|
* Resets cache keys.
|
2010-02-12 12:06:43 -05:00
|
|
|
*
|
|
|
|
* @since 3.0.0
|
2015-09-16 06:03:26 -04:00
|
|
|
* @access public
|
|
|
|
*
|
2015-08-20 18:39:24 -04:00
|
|
|
* @deprecated 3.5.0 Use switch_to_blog()
|
|
|
|
* @see switch_to_blog()
|
2010-02-12 12:06:43 -05:00
|
|
|
*/
|
2014-05-19 01:16:15 -04:00
|
|
|
public function reset() {
|
2012-08-02 14:31:14 -04:00
|
|
|
_deprecated_function( __FUNCTION__, '3.5', 'switch_to_blog()' );
|
|
|
|
|
2010-02-12 12:06:43 -05:00
|
|
|
// Clear out non-global caches since the blog ID has changed.
|
2012-08-02 14:31:14 -04:00
|
|
|
foreach ( array_keys( $this->cache ) as $group ) {
|
|
|
|
if ( ! isset( $this->global_groups[ $group ] ) )
|
|
|
|
unset( $this->cache[ $group ] );
|
2010-02-12 12:06:43 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-02 23:35:47 -05:00
|
|
|
/**
|
2015-09-16 06:03:26 -04:00
|
|
|
* Sets the data contents into the cache.
|
2008-01-02 23:35:47 -05:00
|
|
|
*
|
2008-05-25 11:45:05 -04:00
|
|
|
* The cache contents is grouped by the $group parameter followed by the
|
2011-09-06 17:13:11 -04:00
|
|
|
* $key. This allows for duplicate ids in unique groups. Therefore, naming of
|
2008-05-25 11:45:05 -04:00
|
|
|
* the group should be used with care and should follow normal function
|
|
|
|
* naming guidelines outside of core WordPress usage.
|
2008-01-02 23:35:47 -05:00
|
|
|
*
|
2008-05-25 11:45:05 -04:00
|
|
|
* The $expire parameter is not used, because the cache will automatically
|
|
|
|
* expire for each time a page is accessed and PHP finishes. The method is
|
|
|
|
* more for cache plugins which use files.
|
2008-01-02 23:35:47 -05:00
|
|
|
*
|
2008-08-27 02:45:13 -04:00
|
|
|
* @since 2.0.0
|
2015-09-16 06:03:26 -04:00
|
|
|
* @access public
|
2008-01-02 23:35:47 -05:00
|
|
|
*
|
2015-09-16 06:03:26 -04:00
|
|
|
* @param int|string $key What to call the contents in the cache.
|
|
|
|
* @param mixed $data The contents to store in the cache.
|
|
|
|
* @param string $group Optional. Where to group the cache contents. Default 'default'.
|
|
|
|
* @param int $expire Not Used.
|
|
|
|
* @return true Always returns true.
|
2008-01-02 23:35:47 -05:00
|
|
|
*/
|
2014-05-19 01:16:15 -04:00
|
|
|
public function set( $key, $data, $group = 'default', $expire = 0 ) {
|
2012-03-02 16:10:37 -05:00
|
|
|
if ( empty( $group ) )
|
2005-11-07 16:56:03 -05:00
|
|
|
$group = 'default';
|
|
|
|
|
2012-08-02 14:31:14 -04:00
|
|
|
if ( $this->multisite && ! isset( $this->global_groups[ $group ] ) )
|
|
|
|
$key = $this->blog_prefix . $key;
|
|
|
|
|
|
|
|
if ( is_object( $data ) )
|
2011-04-06 13:44:29 -04:00
|
|
|
$data = clone $data;
|
2008-11-17 16:01:12 -05:00
|
|
|
|
2011-09-06 17:13:11 -04:00
|
|
|
$this->cache[$group][$key] = $data;
|
2006-01-13 19:05:22 -05:00
|
|
|
return true;
|
2005-11-07 16:56:03 -05:00
|
|
|
}
|
|
|
|
|
2008-01-02 23:35:47 -05:00
|
|
|
/**
|
2010-06-06 01:16:32 -04:00
|
|
|
* Echoes the stats of the caching.
|
2008-01-02 23:35:47 -05:00
|
|
|
*
|
2008-05-25 11:45:05 -04:00
|
|
|
* Gives the cache hits, and cache misses. Also prints every cached group,
|
|
|
|
* key and the data.
|
2008-01-02 23:35:47 -05:00
|
|
|
*
|
2008-08-27 02:45:13 -04:00
|
|
|
* @since 2.0.0
|
2015-09-16 06:03:26 -04:00
|
|
|
* @access public
|
2008-01-02 23:35:47 -05:00
|
|
|
*/
|
2014-05-19 01:16:15 -04:00
|
|
|
public function stats() {
|
2005-11-07 16:56:03 -05:00
|
|
|
echo "<p>";
|
2008-01-02 17:13:16 -05:00
|
|
|
echo "<strong>Cache Hits:</strong> {$this->cache_hits}<br />";
|
2007-08-13 23:12:24 -04:00
|
|
|
echo "<strong>Cache Misses:</strong> {$this->cache_misses}<br />";
|
2005-11-07 16:56:03 -05:00
|
|
|
echo "</p>";
|
2010-11-11 05:55:06 -05:00
|
|
|
echo '<ul>';
|
2005-11-07 16:56:03 -05:00
|
|
|
foreach ($this->cache as $group => $cache) {
|
2015-10-21 10:03:25 -04:00
|
|
|
echo "<li><strong>Group:</strong> $group - ( " . number_format( strlen( serialize( $cache ) ) / KB_IN_BYTES, 2 ) . 'k )</li>';
|
2005-11-07 16:56:03 -05:00
|
|
|
}
|
2010-11-11 05:55:06 -05:00
|
|
|
echo '</ul>';
|
2005-11-07 16:56:03 -05:00
|
|
|
}
|
|
|
|
|
2012-08-02 14:31:14 -04:00
|
|
|
/**
|
2016-04-16 08:37:30 -04:00
|
|
|
* Switches the internal blog ID.
|
2012-08-02 14:31:14 -04:00
|
|
|
*
|
2015-09-16 06:03:26 -04:00
|
|
|
* This changes the blog ID used to create keys in blog specific groups.
|
2012-08-02 14:31:14 -04:00
|
|
|
*
|
2012-09-30 10:02:59 -04:00
|
|
|
* @since 3.5.0
|
2015-09-16 06:03:26 -04:00
|
|
|
* @access public
|
2012-09-30 10:02:59 -04:00
|
|
|
*
|
2015-09-16 06:03:26 -04:00
|
|
|
* @param int $blog_id Blog ID.
|
2012-08-02 14:31:14 -04:00
|
|
|
*/
|
2014-05-19 01:16:15 -04:00
|
|
|
public function switch_to_blog( $blog_id ) {
|
2012-08-02 14:31:14 -04:00
|
|
|
$blog_id = (int) $blog_id;
|
|
|
|
$this->blog_prefix = $this->multisite ? $blog_id . ':' : '';
|
|
|
|
}
|
|
|
|
|
2012-03-02 16:10:37 -05:00
|
|
|
/**
|
2015-09-16 06:03:26 -04:00
|
|
|
* Serves as a utility function to determine whether a key exists in the cache.
|
2012-07-20 00:21:42 -04:00
|
|
|
*
|
|
|
|
* @since 3.4.0
|
|
|
|
* @access protected
|
2015-09-16 06:03:26 -04:00
|
|
|
*
|
|
|
|
* @param int|string $key Cache key to check for existence.
|
|
|
|
* @param string $group Cache group for the key existence check.
|
|
|
|
* @return bool Whether the key exists in the cache for the given group.
|
2012-03-02 16:10:37 -05:00
|
|
|
*/
|
2012-07-20 00:21:42 -04:00
|
|
|
protected function _exists( $key, $group ) {
|
|
|
|
return isset( $this->cache[ $group ] ) && ( isset( $this->cache[ $group ][ $key ] ) || array_key_exists( $key, $this->cache[ $group ] ) );
|
2012-03-02 16:10:37 -05:00
|
|
|
}
|
|
|
|
|
2008-01-02 23:35:47 -05:00
|
|
|
/**
|
2015-09-16 06:03:26 -04:00
|
|
|
* Sets up object properties; PHP 5 style constructor.
|
2008-01-02 23:35:47 -05:00
|
|
|
*
|
|
|
|
* @since 2.0.8
|
2015-05-22 00:24:26 -04:00
|
|
|
*
|
2015-09-16 06:03:26 -04:00
|
|
|
* @global int $blog_id Global blog ID.
|
2008-01-02 23:35:47 -05:00
|
|
|
*/
|
2014-05-19 01:16:15 -04:00
|
|
|
public function __construct() {
|
2012-08-02 14:31:14 -04:00
|
|
|
global $blog_id;
|
|
|
|
|
|
|
|
$this->multisite = is_multisite();
|
|
|
|
$this->blog_prefix = $this->multisite ? $blog_id . ':' : '';
|
2012-11-17 10:11:29 -05:00
|
|
|
|
2012-08-02 14:31:14 -04:00
|
|
|
|
2008-05-25 11:45:05 -04:00
|
|
|
/**
|
|
|
|
* @todo This should be moved to the PHP4 style constructor, PHP5
|
|
|
|
* already calls __destruct()
|
|
|
|
*/
|
2012-10-04 16:00:16 -04:00
|
|
|
register_shutdown_function( array( $this, '__destruct' ) );
|
2005-11-07 16:56:03 -05:00
|
|
|
}
|
2007-01-06 18:36:51 -05:00
|
|
|
|
2008-01-02 23:35:47 -05:00
|
|
|
/**
|
2015-09-16 06:03:26 -04:00
|
|
|
* Saves the object cache before object is completely destroyed.
|
2008-01-02 23:35:47 -05:00
|
|
|
*
|
|
|
|
* Called upon object destruction, which should be when PHP ends.
|
|
|
|
*
|
2015-09-16 06:03:26 -04:00
|
|
|
* @since 2.0.8
|
2008-01-02 23:35:47 -05:00
|
|
|
*
|
2015-09-16 06:03:26 -04:00
|
|
|
* @return true Always returns true.
|
2008-01-02 23:35:47 -05:00
|
|
|
*/
|
2014-05-19 01:16:15 -04:00
|
|
|
public function __destruct() {
|
2007-02-27 10:24:54 -05:00
|
|
|
return true;
|
2007-01-06 18:36:51 -05:00
|
|
|
}
|
2005-11-07 16:56:03 -05:00
|
|
|
}
|