2005-11-07 16:56:03 -05:00
|
|
|
<?php
|
|
|
|
function wp_cache_add($key, $data, $flag = '', $expire = 0) {
|
|
|
|
global $wp_object_cache;
|
|
|
|
|
|
|
|
return $wp_object_cache->add($key, $data, $flag, $expire);
|
|
|
|
}
|
|
|
|
|
|
|
|
function wp_cache_close() {
|
2008-01-02 18:03:25 -05:00
|
|
|
return true;
|
2005-11-07 16:56:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function wp_cache_delete($id, $flag = '') {
|
|
|
|
global $wp_object_cache;
|
|
|
|
|
|
|
|
return $wp_object_cache->delete($id, $flag);
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
function wp_cache_get($id, $flag = '') {
|
|
|
|
global $wp_object_cache;
|
|
|
|
|
|
|
|
return $wp_object_cache->get($id, $flag);
|
|
|
|
}
|
|
|
|
|
|
|
|
function wp_cache_init() {
|
2006-11-18 19:12:57 -05:00
|
|
|
$GLOBALS['wp_object_cache'] =& new WP_Object_Cache();
|
2005-11-07 16:56:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function wp_cache_replace($key, $data, $flag = '', $expire = 0) {
|
|
|
|
global $wp_object_cache;
|
|
|
|
|
|
|
|
return $wp_object_cache->replace($key, $data, $flag, $expire);
|
|
|
|
}
|
|
|
|
|
|
|
|
function wp_cache_set($key, $data, $flag = '', $expire = 0) {
|
|
|
|
global $wp_object_cache;
|
|
|
|
|
|
|
|
return $wp_object_cache->set($key, $data, $flag, $expire);
|
|
|
|
}
|
|
|
|
|
|
|
|
class WP_Object_Cache {
|
|
|
|
var $cache = array ();
|
2005-11-14 17:32:03 -05:00
|
|
|
var $non_existant_objects = array ();
|
2005-12-19 14:14:22 -05:00
|
|
|
var $global_groups = array ('users', 'userlogins', 'usermeta');
|
2008-01-02 17:13:16 -05:00
|
|
|
var $cache_hits = 0;
|
2005-11-07 16:56:03 -05:00
|
|
|
var $cache_misses = 0;
|
2006-01-13 19:05:22 -05:00
|
|
|
|
2005-11-07 16:56:03 -05:00
|
|
|
function add($id, $data, $group = 'default', $expire = '') {
|
2005-11-14 17:32:03 -05:00
|
|
|
if (empty ($group))
|
2005-11-07 16:56:03 -05:00
|
|
|
$group = 'default';
|
|
|
|
|
2005-11-14 17:32:03 -05:00
|
|
|
if (false !== $this->get($id, $group, false))
|
2005-11-07 16:56:03 -05:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return $this->set($id, $data, $group, $expire);
|
|
|
|
}
|
|
|
|
|
2005-11-14 16:29:30 -05:00
|
|
|
function delete($id, $group = 'default', $force = false) {
|
2005-11-14 17:32:03 -05:00
|
|
|
if (empty ($group))
|
2005-11-07 16:56:03 -05:00
|
|
|
$group = 'default';
|
|
|
|
|
2005-11-14 17:32:03 -05:00
|
|
|
if (!$force && false === $this->get($id, $group, false))
|
2005-11-07 16:56:03 -05:00
|
|
|
return false;
|
|
|
|
|
|
|
|
unset ($this->cache[$group][$id]);
|
2005-11-09 06:10:34 -05:00
|
|
|
$this->non_existant_objects[$group][$id] = true;
|
2005-11-07 16:56:03 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2005-11-14 17:10:28 -05:00
|
|
|
function flush() {
|
2005-11-14 17:32:03 -05: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 17:13:16 -05:00
|
|
|
function get($id, $group = 'default') {
|
2005-11-14 17:32:03 -05:00
|
|
|
if (empty ($group))
|
2005-11-07 16:56:03 -05:00
|
|
|
$group = 'default';
|
|
|
|
|
|
|
|
if (isset ($this->cache[$group][$id])) {
|
2008-01-02 17:13:16 -05:00
|
|
|
$this->cache_hits += 1;
|
2005-11-07 16:56:03 -05:00
|
|
|
return $this->cache[$group][$id];
|
|
|
|
}
|
|
|
|
|
2008-01-02 17:13:16 -05:00
|
|
|
if ( isset ($this->non_existant_objects[$group][$id]) )
|
2005-11-07 16:56:03 -05:00
|
|
|
return false;
|
2006-11-19 02:56:05 -05:00
|
|
|
|
2008-01-02 17:13:16 -05:00
|
|
|
$this->non_existant_objects[$group][$id] = true;
|
|
|
|
$this->cache_misses += 1;
|
|
|
|
return false;
|
2006-01-13 19:05:22 -05:00
|
|
|
}
|
|
|
|
|
2005-11-07 16:56:03 -05:00
|
|
|
function replace($id, $data, $group = 'default', $expire = '') {
|
2005-11-14 17:32:03 -05:00
|
|
|
if (empty ($group))
|
2005-11-07 16:56:03 -05:00
|
|
|
$group = 'default';
|
|
|
|
|
2005-11-14 17:32:03 -05:00
|
|
|
if (false === $this->get($id, $group, false))
|
2005-11-07 16:56:03 -05:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return $this->set($id, $data, $group, $expire);
|
|
|
|
}
|
|
|
|
|
|
|
|
function set($id, $data, $group = 'default', $expire = '') {
|
2005-11-14 17:32:03 -05:00
|
|
|
if (empty ($group))
|
2005-11-07 16:56:03 -05:00
|
|
|
$group = 'default';
|
|
|
|
|
2007-10-13 21:08:07 -04:00
|
|
|
if (NULL === $data)
|
2005-11-09 06:10:34 -05:00
|
|
|
$data = '';
|
|
|
|
|
2005-11-07 16:56:03 -05:00
|
|
|
$this->cache[$group][$id] = $data;
|
2005-11-14 17:32:03 -05:00
|
|
|
unset ($this->non_existant_objects[$group][$id]);
|
2006-01-13 19:05:22 -05:00
|
|
|
|
|
|
|
return true;
|
2005-11-07 16:56:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function stats() {
|
|
|
|
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>";
|
|
|
|
|
|
|
|
foreach ($this->cache as $group => $cache) {
|
|
|
|
echo "<p>";
|
2007-08-13 23:12:24 -04:00
|
|
|
echo "<strong>Group:</strong> $group<br />";
|
2005-11-07 16:56:03 -05:00
|
|
|
echo "<strong>Cache:</strong>";
|
|
|
|
echo "<pre>";
|
|
|
|
print_r($cache);
|
|
|
|
echo "</pre>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function WP_Object_Cache() {
|
2007-01-06 18:36:51 -05:00
|
|
|
return $this->__construct();
|
|
|
|
}
|
2007-02-27 10:24:54 -05:00
|
|
|
|
2007-01-06 18:36:51 -05:00
|
|
|
function __construct() {
|
|
|
|
register_shutdown_function(array(&$this, "__destruct"));
|
2005-11-07 16:56:03 -05:00
|
|
|
}
|
2007-01-06 18:36:51 -05:00
|
|
|
|
|
|
|
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
|
|
|
}
|
2005-12-19 14:14:22 -05:00
|
|
|
?>
|