diff options
| author | donncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36> | 2005-11-09 09:07:54 +0000 |
|---|---|---|
| committer | donncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36> | 2005-11-09 09:07:54 +0000 |
| commit | 91d71b710006ba158edefcc442d862dd533645a5 (patch) | |
| tree | 3b8e2cf3851db0e494d516bea51ada3ca02c347f /wp-inst/wp-includes/cache.php | |
| parent | e4490a2b22017697ac29227dd202ce9500484edc (diff) | |
| download | wordpress-mu-91d71b710006ba158edefcc442d862dd533645a5.tar.gz wordpress-mu-91d71b710006ba158edefcc442d862dd533645a5.tar.xz wordpress-mu-91d71b710006ba158edefcc442d862dd533645a5.zip | |
WP Merge
git-svn-id: http://svn.automattic.com/wordpress-mu/trunk@427 7be80a69-a1ef-0310-a953-fb0f7c49ff36
Diffstat (limited to 'wp-inst/wp-includes/cache.php')
| -rw-r--r-- | wp-inst/wp-includes/cache.php | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/wp-inst/wp-includes/cache.php b/wp-inst/wp-includes/cache.php index 1581583..8a90def 100644 --- a/wp-inst/wp-includes/cache.php +++ b/wp-inst/wp-includes/cache.php @@ -45,6 +45,9 @@ function wp_cache_set($key, $data, $flag = '', $expire = 0) { return $wp_object_cache->set($key, $data, $flag, $expire); } +define('CACHE_SERIAL_HEADER', "<?php\n//"); +define('CACHE_SERIAL_FOOTER', "\n?".">"); + class WP_Object_Cache { var $cache_dir; var $cache_enabled = false; @@ -105,12 +108,12 @@ class WP_Object_Cache { return false; } - $cache_file = $this->cache_dir . $this->get_group_dir($group) . "/" . md5($id); + $cache_file = $this->cache_dir . $this->get_group_dir($group) . "/" . md5($id . DB_PASSWORD) . '.php'; if (!file_exists($cache_file)) { $this->cache_misses += 1; return false; } - $this->cache[$group][$id] = unserialize(@ file_get_contents($cache_file)); + $this->cache[$group][$id] = unserialize(substr(@ file_get_contents($cache_file), strlen(CACHE_SERIAL_HEADER), -strlen(CACHE_SERIAL_FOOTER))); if ( false === $this->cache[$group][$id]) $this->cache[$group][$id] = ''; $this->cold_cache_hits += 1; @@ -166,6 +169,10 @@ class WP_Object_Cache { break; @ chmod($this->cache_dir . $make_dir, $perms); } + + if (!file_exists($this->cache_dir . $make_dir . "index.php")) { + touch($this->cache_dir . $make_dir . "index.php"); + } } return $this->cache_dir . "$group_dir/"; @@ -209,6 +216,10 @@ class WP_Object_Cache { return; @ chmod($this->cache_dir, $dir_perms); } + + if (!file_exists($this->cache_dir . "index.php")) { + touch($this->cache_dir . "index.php"); + } // Acquire a write lock. Semaphore preferred. Fallback to flock. if (function_exists('sem_get')) { @@ -229,13 +240,17 @@ class WP_Object_Cache { foreach ($ids as $id) { // TODO: If the id is no longer in the cache, it was deleted and // the file should be removed. - $cache_file = $group_dir . md5($id); + $cache_file = $group_dir . md5($id . DB_PASSWORD) . '.php'; $temp_file = tempnam($group_dir, 'tmp'); - $serial = serialize($this->cache[$group][$id]); + $serial = CACHE_SERIAL_HEADER . serialize($this->cache[$group][$id]) . CACHE_SERIAL_FOOTER; $fd = fopen($temp_file, 'w'); fputs($fd, $serial); - fclose($fd); - rename($temp_file, $cache_file); + fclose($fd); + if (!@rename($temp_file, $cache_file)) { + if (copy ($temp_file, $cache_file)) { + unlink($temp_file); + } + } } } |
