2005-11-07 16:56:03 -05:00
|
|
|
<?php
|
|
|
|
function wp_cache_add($key, $data, $flag = '', $expire = 0) {
|
|
|
|
global $wp_object_cache;
|
2007-02-01 04:16:15 -05:00
|
|
|
$data = unserialize(serialize($data));
|
2005-11-07 16:56:03 -05:00
|
|
|
|
|
|
|
return $wp_object_cache->add($key, $data, $flag, $expire);
|
|
|
|
}
|
|
|
|
|
|
|
|
function wp_cache_close() {
|
|
|
|
global $wp_object_cache;
|
|
|
|
|
2007-01-06 18:36:51 -05:00
|
|
|
if ( ! isset($wp_object_cache) )
|
|
|
|
return;
|
2005-11-07 16:56:03 -05:00
|
|
|
return $wp_object_cache->save();
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2007-02-01 04:16:15 -05:00
|
|
|
$data = unserialize(serialize($data));
|
2005-11-07 16:56:03 -05:00
|
|
|
|
|
|
|
return $wp_object_cache->replace($key, $data, $flag, $expire);
|
|
|
|
}
|
|
|
|
|
|
|
|
function wp_cache_set($key, $data, $flag = '', $expire = 0) {
|
|
|
|
global $wp_object_cache;
|
2007-02-01 04:16:15 -05:00
|
|
|
$data = unserialize(serialize($data));
|
2005-11-07 16:56:03 -05:00
|
|
|
|
|
|
|
return $wp_object_cache->set($key, $data, $flag, $expire);
|
|
|
|
}
|
|
|
|
|
2006-05-26 17:14:36 -04:00
|
|
|
define('CACHE_SERIAL_HEADER', "<?php\n/*");
|
|
|
|
define('CACHE_SERIAL_FOOTER', "*/\n?".">");
|
2005-11-08 21:38:17 -05:00
|
|
|
|
2005-11-07 16:56:03 -05:00
|
|
|
class WP_Object_Cache {
|
|
|
|
var $cache_dir;
|
|
|
|
var $cache_enabled = false;
|
2005-12-31 17:34:58 -05:00
|
|
|
var $expiration_time = 900;
|
2005-11-07 16:56:03 -05:00
|
|
|
var $flock_filename = 'wp_object_cache.lock';
|
2006-01-13 19:05:22 -05:00
|
|
|
var $mutex;
|
2005-11-07 16:56:03 -05:00
|
|
|
var $cache = array ();
|
|
|
|
var $dirty_objects = 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');
|
2005-11-07 16:56:03 -05:00
|
|
|
var $blog_id;
|
|
|
|
var $cold_cache_hits = 0;
|
|
|
|
var $warm_cache_hits = 0;
|
|
|
|
var $cache_misses = 0;
|
2006-05-30 21:40:00 -04:00
|
|
|
var $secret = '';
|
2005-11-07 16:56:03 -05:00
|
|
|
|
2006-01-13 19:05:22 -05:00
|
|
|
function acquire_lock() {
|
2006-11-19 02:56:05 -05:00
|
|
|
// Acquire a write lock.
|
2006-01-13 19:05:22 -05:00
|
|
|
$this->mutex = @fopen($this->cache_dir.$this->flock_filename, 'w');
|
|
|
|
if ( false == $this->mutex)
|
|
|
|
return false;
|
|
|
|
flock($this->mutex, LOCK_EX);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
$this->dirty_objects[$group][] = $id;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2005-11-14 17:10:28 -05:00
|
|
|
function flush() {
|
2005-11-16 14:01:58 -05:00
|
|
|
if ( !$this->cache_enabled )
|
2006-01-13 19:05:22 -05:00
|
|
|
return true;
|
|
|
|
|
|
|
|
if ( ! $this->acquire_lock() )
|
|
|
|
return false;
|
2006-02-12 02:53:23 -05:00
|
|
|
|
2006-01-04 21:56:42 -05:00
|
|
|
$this->rm_cache_dir();
|
2005-11-14 17:32:03 -05:00
|
|
|
$this->cache = array ();
|
|
|
|
$this->dirty_objects = array ();
|
|
|
|
$this->non_existant_objects = array ();
|
2006-02-12 02:53:23 -05:00
|
|
|
|
2006-01-13 19:05:22 -05:00
|
|
|
$this->release_lock();
|
|
|
|
|
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
|
|
|
|
2005-11-09 06:10:34 -05:00
|
|
|
function get($id, $group = 'default', $count_hits = true) {
|
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])) {
|
2005-11-14 17:32:03 -05:00
|
|
|
if ($count_hits)
|
2005-11-09 06:10:34 -05:00
|
|
|
$this->warm_cache_hits += 1;
|
2005-11-07 16:56:03 -05:00
|
|
|
return $this->cache[$group][$id];
|
|
|
|
}
|
|
|
|
|
2005-11-14 17:32:03 -05:00
|
|
|
if (isset ($this->non_existant_objects[$group][$id]))
|
2005-11-09 06:10:34 -05:00
|
|
|
return false;
|
|
|
|
|
2005-11-07 16:56:03 -05:00
|
|
|
// If caching is not enabled, we have to fall back to pulling from the DB.
|
|
|
|
if (!$this->cache_enabled) {
|
|
|
|
if (!isset ($this->cache[$group]))
|
|
|
|
$this->load_group_from_db($group);
|
|
|
|
|
|
|
|
if (isset ($this->cache[$group][$id])) {
|
|
|
|
$this->cold_cache_hits += 1;
|
|
|
|
return $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
|
|
|
$this->cache_misses += 1;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2006-05-30 20:24:03 -04:00
|
|
|
$cache_file = $this->cache_dir.$this->get_group_dir($group)."/".$this->hash($id).'.php';
|
2005-11-07 16:56:03 -05:00
|
|
|
if (!file_exists($cache_file)) {
|
2005-11-09 06:10:34 -05:00
|
|
|
$this->non_existant_objects[$group][$id] = true;
|
2005-11-07 16:56:03 -05:00
|
|
|
$this->cache_misses += 1;
|
|
|
|
return false;
|
|
|
|
}
|
2005-11-09 06:10:34 -05:00
|
|
|
|
|
|
|
// If the object has expired, remove it from the cache and return false to force
|
|
|
|
// a refresh.
|
|
|
|
$now = time();
|
2005-11-14 17:32:03 -05:00
|
|
|
if ((filemtime($cache_file) + $this->expiration_time) <= $now) {
|
2005-11-09 06:10:34 -05:00
|
|
|
$this->cache_misses += 1;
|
2005-11-14 16:29:30 -05:00
|
|
|
$this->delete($id, $group, true);
|
2005-11-09 06:10:34 -05:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2006-05-26 17:14:36 -04:00
|
|
|
$this->cache[$group][$id] = unserialize(base64_decode(substr(@ file_get_contents($cache_file), strlen(CACHE_SERIAL_HEADER), -strlen(CACHE_SERIAL_FOOTER))));
|
2005-11-14 17:32:03 -05:00
|
|
|
if (false === $this->cache[$group][$id])
|
2005-11-07 16:56:03 -05:00
|
|
|
$this->cache[$group][$id] = '';
|
2005-11-09 06:10:34 -05:00
|
|
|
|
2005-11-07 16:56:03 -05:00
|
|
|
$this->cold_cache_hits += 1;
|
|
|
|
return $this->cache[$group][$id];
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_group_dir($group) {
|
2005-11-14 17:32:03 -05:00
|
|
|
if (false !== array_search($group, $this->global_groups))
|
2005-11-07 16:56:03 -05:00
|
|
|
return $group;
|
|
|
|
|
|
|
|
return "{$this->blog_id}/$group";
|
|
|
|
}
|
|
|
|
|
2006-05-30 20:24:03 -04:00
|
|
|
function hash($data) {
|
|
|
|
if ( function_exists('hash_hmac') ) {
|
2006-05-30 21:40:00 -04:00
|
|
|
return hash_hmac('md5', $data, $this->secret);
|
2006-05-30 20:24:03 -04:00
|
|
|
} else {
|
2006-05-30 21:40:00 -04:00
|
|
|
return md5($data . $this->secret);
|
2006-05-30 20:24:03 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-07 16:56:03 -05:00
|
|
|
function load_group_from_db($group) {
|
|
|
|
global $wpdb;
|
|
|
|
|
|
|
|
if ('category' == $group) {
|
|
|
|
$this->cache['category'] = array ();
|
|
|
|
if ($dogs = $wpdb->get_results("SELECT * FROM $wpdb->categories")) {
|
|
|
|
foreach ($dogs as $catt)
|
|
|
|
$this->cache['category'][$catt->cat_ID] = $catt;
|
|
|
|
}
|
2007-02-01 03:53:08 -05:00
|
|
|
}
|
|
|
|
|
2005-11-07 16:56:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function make_group_dir($group, $perms) {
|
|
|
|
$group_dir = $this->get_group_dir($group);
|
|
|
|
$make_dir = '';
|
2005-11-14 17:32:03 -05:00
|
|
|
foreach (split('/', $group_dir) as $subdir) {
|
2005-11-07 16:56:03 -05:00
|
|
|
$make_dir .= "$subdir/";
|
2005-11-14 17:32:03 -05:00
|
|
|
if (!file_exists($this->cache_dir.$make_dir)) {
|
2005-11-16 18:40:14 -05:00
|
|
|
if (! @ mkdir($this->cache_dir.$make_dir))
|
2005-11-14 17:32:03 -05:00
|
|
|
break;
|
|
|
|
@ chmod($this->cache_dir.$make_dir, $perms);
|
2005-11-07 16:56:03 -05:00
|
|
|
}
|
2005-11-08 17:15:06 -05:00
|
|
|
|
2005-11-14 17:32:03 -05:00
|
|
|
if (!file_exists($this->cache_dir.$make_dir."index.php")) {
|
2006-01-01 21:50:59 -05:00
|
|
|
$file_perms = $perms & 0000666;
|
2005-11-16 18:40:14 -05:00
|
|
|
@ touch($this->cache_dir.$make_dir."index.php");
|
2006-01-01 21:50:59 -05:00
|
|
|
@ chmod($this->cache_dir.$make_dir."index.php", $file_perms);
|
2005-11-08 17:15:06 -05:00
|
|
|
}
|
2005-11-07 16:56:03 -05:00
|
|
|
}
|
2005-11-14 17:32:03 -05:00
|
|
|
|
|
|
|
return $this->cache_dir."$group_dir/";
|
2005-11-07 16:56:03 -05:00
|
|
|
}
|
|
|
|
|
2006-01-04 21:56:42 -05:00
|
|
|
function rm_cache_dir() {
|
|
|
|
$dir = $this->cache_dir;
|
|
|
|
$dir = rtrim($dir, DIRECTORY_SEPARATOR);
|
2006-01-04 23:50:58 -05:00
|
|
|
$top_dir = $dir;
|
2006-01-04 21:56:42 -05:00
|
|
|
$stack = array($dir);
|
2006-01-19 17:12:15 -05:00
|
|
|
$index = 0;
|
2006-01-04 21:56:42 -05:00
|
|
|
|
2006-01-19 17:12:15 -05:00
|
|
|
while ($index < count($stack)) {
|
|
|
|
# Get indexed directory from stack
|
|
|
|
$dir = $stack[$index];
|
2006-11-19 02:56:05 -05:00
|
|
|
|
2006-01-04 21:56:42 -05:00
|
|
|
$dh = @ opendir($dir);
|
|
|
|
if (!$dh)
|
|
|
|
return false;
|
2006-11-19 02:56:05 -05:00
|
|
|
|
2006-01-04 21:56:42 -05:00
|
|
|
while (($file = @ readdir($dh)) !== false) {
|
|
|
|
if ($file == '.' or $file == '..')
|
|
|
|
continue;
|
2006-02-12 02:53:23 -05:00
|
|
|
|
2006-01-04 21:56:42 -05:00
|
|
|
if (@ is_dir($dir . DIRECTORY_SEPARATOR . $file))
|
|
|
|
$stack[] = $dir . DIRECTORY_SEPARATOR . $file;
|
|
|
|
else if (@ is_file($dir . DIRECTORY_SEPARATOR . $file))
|
|
|
|
@ unlink($dir . DIRECTORY_SEPARATOR . $file);
|
2005-11-14 17:32:03 -05:00
|
|
|
}
|
2006-01-04 21:56:42 -05:00
|
|
|
|
2006-01-19 17:12:15 -05:00
|
|
|
$index++;
|
2006-01-04 21:56:42 -05:00
|
|
|
}
|
2006-01-19 17:12:15 -05:00
|
|
|
|
|
|
|
$stack = array_reverse($stack); // Last added dirs are deepest
|
|
|
|
foreach($stack as $dir) {
|
|
|
|
if ( $dir != $top_dir)
|
|
|
|
@ rmdir($dir);
|
|
|
|
}
|
|
|
|
|
2005-11-14 17:10:28 -05:00
|
|
|
}
|
|
|
|
|
2006-01-13 19:05:22 -05:00
|
|
|
function release_lock() {
|
|
|
|
// Release write lock.
|
|
|
|
flock($this->mutex, LOCK_UN);
|
|
|
|
fclose($this->mutex);
|
|
|
|
}
|
|
|
|
|
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';
|
|
|
|
|
2005-11-14 17:32:03 -05: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]);
|
2005-11-07 16:56:03 -05:00
|
|
|
$this->dirty_objects[$group][] = $id;
|
2005-11-09 06:10:34 -05:00
|
|
|
|
2005-11-07 16:56:03 -05:00
|
|
|
return true;
|
|
|
|
}
|
2005-11-09 06:10:34 -05:00
|
|
|
|
2005-11-07 16:56:03 -05:00
|
|
|
function save() {
|
2005-11-08 17:28:45 -05:00
|
|
|
//$this->stats();
|
2005-11-07 16:56:03 -05:00
|
|
|
|
|
|
|
if (!$this->cache_enabled)
|
2006-01-13 19:05:22 -05:00
|
|
|
return true;
|
2005-11-07 16:56:03 -05:00
|
|
|
|
|
|
|
if (empty ($this->dirty_objects))
|
2006-01-13 19:05:22 -05:00
|
|
|
return true;
|
2005-11-07 16:56:03 -05:00
|
|
|
|
|
|
|
// Give the new dirs the same perms as wp-content.
|
|
|
|
$stat = stat(ABSPATH.'wp-content');
|
2006-01-01 21:50:59 -05:00
|
|
|
$dir_perms = $stat['mode'] & 0007777; // Get the permission bits.
|
|
|
|
$file_perms = $dir_perms & 0000666; // Remove execute bits for files.
|
2005-11-07 16:56:03 -05:00
|
|
|
|
|
|
|
// Make the base cache dir.
|
|
|
|
if (!file_exists($this->cache_dir)) {
|
2005-11-22 02:45:07 -05:00
|
|
|
if (! @ mkdir($this->cache_dir))
|
2006-01-13 19:05:22 -05:00
|
|
|
return false;
|
2005-11-07 16:56:03 -05:00
|
|
|
@ chmod($this->cache_dir, $dir_perms);
|
|
|
|
}
|
2005-11-14 17:32:03 -05:00
|
|
|
|
|
|
|
if (!file_exists($this->cache_dir."index.php")) {
|
2005-11-16 18:40:14 -05:00
|
|
|
@ touch($this->cache_dir."index.php");
|
2006-01-01 21:50:59 -05:00
|
|
|
@ chmod($this->cache_dir."index.php", $file_perms);
|
2005-11-08 17:15:06 -05:00
|
|
|
}
|
2005-11-07 16:56:03 -05:00
|
|
|
|
2006-01-13 19:05:22 -05:00
|
|
|
if ( ! $this->acquire_lock() )
|
|
|
|
return false;
|
2005-11-07 16:56:03 -05:00
|
|
|
|
|
|
|
// Loop over dirty objects and save them.
|
2006-01-13 19:05:22 -05:00
|
|
|
$errors = 0;
|
2005-11-07 16:56:03 -05:00
|
|
|
foreach ($this->dirty_objects as $group => $ids) {
|
|
|
|
$group_dir = $this->make_group_dir($group, $dir_perms);
|
|
|
|
|
|
|
|
$ids = array_unique($ids);
|
|
|
|
foreach ($ids as $id) {
|
2006-05-30 20:24:03 -04:00
|
|
|
$cache_file = $group_dir.$this->hash($id).'.php';
|
2005-11-09 06:10:34 -05:00
|
|
|
|
|
|
|
// Remove the cache file if the key is not set.
|
2005-11-14 17:32:03 -05:00
|
|
|
if (!isset ($this->cache[$group][$id])) {
|
|
|
|
if (file_exists($cache_file))
|
2006-01-13 19:05:22 -05:00
|
|
|
@ unlink($cache_file);
|
2005-11-09 06:10:34 -05:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2005-11-07 16:56:03 -05:00
|
|
|
$temp_file = tempnam($group_dir, 'tmp');
|
2006-05-26 17:14:36 -04:00
|
|
|
$serial = CACHE_SERIAL_HEADER.base64_encode(serialize($this->cache[$group][$id])).CACHE_SERIAL_FOOTER;
|
2005-11-19 15:12:26 -05:00
|
|
|
$fd = @fopen($temp_file, 'w');
|
2006-01-13 19:05:22 -05:00
|
|
|
if ( false === $fd ) {
|
|
|
|
$errors++;
|
2005-11-19 15:12:26 -05:00
|
|
|
continue;
|
2006-01-13 19:05:22 -05:00
|
|
|
}
|
2005-11-07 16:56:03 -05:00
|
|
|
fputs($fd, $serial);
|
2005-11-14 17:32:03 -05:00
|
|
|
fclose($fd);
|
|
|
|
if (!@ rename($temp_file, $cache_file)) {
|
2007-04-12 12:31:47 -04:00
|
|
|
if (!@ copy($temp_file, $cache_file))
|
2006-02-12 02:53:23 -05:00
|
|
|
$errors++;
|
2007-04-12 12:31:47 -04:00
|
|
|
@ unlink($temp_file);
|
2005-11-08 21:38:17 -05:00
|
|
|
}
|
2006-01-01 21:50:59 -05:00
|
|
|
@ chmod($cache_file, $file_perms);
|
2005-11-07 16:56:03 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-05 21:10:43 -05:00
|
|
|
$this->dirty_objects = array();
|
|
|
|
|
2006-01-13 19:05:22 -05:00
|
|
|
$this->release_lock();
|
2006-02-12 02:53:23 -05:00
|
|
|
|
2006-01-13 19:05:22 -05:00
|
|
|
if ( $errors )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
2005-11-07 16:56:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function stats() {
|
|
|
|
echo "<p>";
|
|
|
|
echo "<strong>Cold Cache Hits:</strong> {$this->cold_cache_hits}<br/>";
|
|
|
|
echo "<strong>Warm Cache Hits:</strong> {$this->warm_cache_hits}<br/>";
|
|
|
|
echo "<strong>Cache Misses:</strong> {$this->cache_misses}<br/>";
|
|
|
|
echo "</p>";
|
|
|
|
|
|
|
|
foreach ($this->cache as $group => $cache) {
|
|
|
|
echo "<p>";
|
|
|
|
echo "<strong>Group:</strong> $group<br/>";
|
|
|
|
echo "<strong>Cache:</strong>";
|
|
|
|
echo "<pre>";
|
|
|
|
print_r($cache);
|
|
|
|
echo "</pre>";
|
2005-11-14 17:32:03 -05:00
|
|
|
if (isset ($this->dirty_objects[$group])) {
|
2005-11-07 16:56:03 -05:00
|
|
|
echo "<strong>Dirty Objects:</strong>";
|
|
|
|
echo "<pre>";
|
|
|
|
print_r(array_unique($this->dirty_objects[$group]));
|
|
|
|
echo "</pre>";
|
|
|
|
echo "</p>";
|
2005-11-14 17:32:03 -05:00
|
|
|
}
|
2005-11-07 16:56:03 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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() {
|
2006-05-30 21:40:25 -04:00
|
|
|
global $blog_id;
|
2005-11-07 16:56:03 -05:00
|
|
|
|
2007-01-06 18:36:51 -05:00
|
|
|
register_shutdown_function(array(&$this, "__destruct"));
|
|
|
|
|
2005-11-14 17:32:03 -05:00
|
|
|
if (defined('DISABLE_CACHE'))
|
2005-11-07 16:56:03 -05:00
|
|
|
return;
|
|
|
|
|
2006-02-03 22:21:09 -05:00
|
|
|
if ( ! defined('ENABLE_CACHE') )
|
|
|
|
return;
|
|
|
|
|
2006-01-14 16:22:48 -05:00
|
|
|
// Disable the persistent cache if safe_mode is on.
|
2006-01-18 17:21:40 -05:00
|
|
|
if ( ini_get('safe_mode') && ! defined('ENABLE_CACHE') )
|
2006-01-14 16:22:48 -05:00
|
|
|
return;
|
|
|
|
|
2005-11-14 17:32:03 -05:00
|
|
|
if (defined('CACHE_PATH'))
|
2005-11-07 16:56:03 -05:00
|
|
|
$this->cache_dir = CACHE_PATH;
|
|
|
|
else
|
2006-01-19 17:12:15 -05:00
|
|
|
// Using the correct separator eliminates some cache flush errors on Windows
|
|
|
|
$this->cache_dir = ABSPATH.'wp-content'.DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR;
|
2005-11-07 16:56:03 -05:00
|
|
|
|
2005-11-16 21:24:52 -05:00
|
|
|
if (is_writable($this->cache_dir) && is_dir($this->cache_dir)) {
|
2005-11-07 16:56:03 -05:00
|
|
|
$this->cache_enabled = true;
|
2006-01-14 16:22:48 -05:00
|
|
|
} else {
|
2005-11-14 17:32:03 -05:00
|
|
|
if (is_writable(ABSPATH.'wp-content')) {
|
|
|
|
$this->cache_enabled = true;
|
|
|
|
}
|
2006-01-14 16:22:48 -05:00
|
|
|
}
|
2005-11-09 06:10:34 -05:00
|
|
|
|
2005-11-14 17:32:03 -05:00
|
|
|
if (defined('CACHE_EXPIRATION_TIME'))
|
2005-11-09 06:10:34 -05:00
|
|
|
$this->expiration_time = CACHE_EXPIRATION_TIME;
|
|
|
|
|
2006-05-30 21:40:00 -04:00
|
|
|
if ( defined('WP_SECRET') )
|
|
|
|
$this->secret = WP_SECRET;
|
|
|
|
else
|
|
|
|
$this->secret = DB_PASSWORD . DB_USER . DB_NAME . DB_HOST . ABSPATH;
|
|
|
|
|
2006-05-30 20:24:03 -04:00
|
|
|
$this->blog_id = $this->hash($blog_id);
|
2005-11-07 16:56:03 -05:00
|
|
|
}
|
2007-01-06 18:36:51 -05:00
|
|
|
|
|
|
|
function __destruct() {
|
|
|
|
$this->save();
|
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
|
|
|
?>
|