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