Changeset 3088
- Timestamp:
- 11/14/05 22:32:03 (3 years ago)
- Files:
-
- trunk/wp-admin/install.php (modified) (2 diffs)
- trunk/wp-includes/cache.php (modified) (18 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/wp-admin/install.php
r3067 r3088 138 138 139 139 // Set everything up 140 wp_cache_flush(); 140 141 make_db_current_silent(); 141 142 populate_options(); … … 199 200 @wp_mail($admin_email, __('New WordPress Blog'), $message, $message_headers); 200 201 202 wp_cache_flush(); 201 203 ?> 202 204 trunk/wp-includes/cache.php
r3087 r3088 20 20 function wp_cache_flush() { 21 21 global $wp_object_cache; 22 22 23 23 return $wp_object_cache->flush(); 24 24 } … … 61 61 var $cache = array (); 62 62 var $dirty_objects = array (); 63 var $non_existant_objects = array ();64 var $global_groups = array ('users', 'usermeta');63 var $non_existant_objects = array (); 64 var $global_groups = array ('users', 'usermeta'); 65 65 var $blog_id; 66 66 var $cold_cache_hits = 0; … … 69 69 70 70 function add($id, $data, $group = 'default', $expire = '') { 71 if ( empty($group))72 $group = 'default'; 73 74 if ( false !== $this->get($id, $group, false))71 if (empty ($group)) 72 $group = 'default'; 73 74 if (false !== $this->get($id, $group, false)) 75 75 return false; 76 76 … … 79 79 80 80 function delete($id, $group = 'default', $force = false) { 81 if ( empty($group))82 $group = 'default'; 83 84 if ( !$force && false === $this->get($id, $group, false))81 if (empty ($group)) 82 $group = 'default'; 83 84 if (!$force && false === $this->get($id, $group, false)) 85 85 return false; 86 86 … … 92 92 93 93 function flush() { 94 return $this->rm($this->cache_dir . '*'); 95 } 96 94 $this->rm($this->cache_dir.'*'); 95 $this->cache = array (); 96 $this->dirty_objects = array (); 97 $this->non_existant_objects = array (); 98 return true; 99 } 100 97 101 function get($id, $group = 'default', $count_hits = true) { 98 if ( empty($group))102 if (empty ($group)) 99 103 $group = 'default'; 100 104 101 105 if (isset ($this->cache[$group][$id])) { 102 if ( $count_hits)106 if ($count_hits) 103 107 $this->warm_cache_hits += 1; 104 108 return $this->cache[$group][$id]; 105 109 } 106 110 107 if ( isset($this->non_existant_objects[$group][$id]))111 if (isset ($this->non_existant_objects[$group][$id])) 108 112 return false; 109 113 … … 123 127 } 124 128 125 $cache_file = $this->cache_dir . $this->get_group_dir($group) . "/" . md5($id . DB_PASSWORD) .'.php';129 $cache_file = $this->cache_dir.$this->get_group_dir($group)."/".md5($id.DB_PASSWORD).'.php'; 126 130 if (!file_exists($cache_file)) { 127 131 $this->non_existant_objects[$group][$id] = true; … … 133 137 // a refresh. 134 138 $now = time(); 135 if ( (filemtime($cache_file) + $this->expiration_time) <= $now) {139 if ((filemtime($cache_file) + $this->expiration_time) <= $now) { 136 140 $this->cache_misses += 1; 137 141 $this->delete($id, $group, true); … … 140 144 141 145 $this->cache[$group][$id] = unserialize(substr(@ file_get_contents($cache_file), strlen(CACHE_SERIAL_HEADER), -strlen(CACHE_SERIAL_FOOTER))); 142 if ( false === $this->cache[$group][$id])146 if (false === $this->cache[$group][$id]) 143 147 $this->cache[$group][$id] = ''; 144 148 … … 148 152 149 153 function get_group_dir($group) { 150 if ( false !== array_search($group, $this->global_groups))154 if (false !== array_search($group, $this->global_groups)) 151 155 return $group; 152 156 … … 173 177 } 174 178 } 175 } else if ( 'options' == $group ) { 176 $wpdb->hide_errors(); 177 if ( !$options = $wpdb->get_results("SELECT option_name, option_value FROM $wpdb->options WHERE autoload = 'yes'") ) { 178 $options = $wpdb->get_results("SELECT option_name, option_value FROM $wpdb->options"); 179 } 180 $wpdb->show_errors(); 181 182 foreach ($options as $option) { 183 $this->cache['options'][$option->option_name] = $option->option_value; 184 } 185 } 179 } else 180 if ('options' == $group) { 181 $wpdb->hide_errors(); 182 if (!$options = $wpdb->get_results("SELECT option_name, option_value FROM $wpdb->options WHERE autoload = 'yes'")) { 183 $options = $wpdb->get_results("SELECT option_name, option_value FROM $wpdb->options"); 184 } 185 $wpdb->show_errors(); 186 187 foreach ($options as $option) { 188 $this->cache['options'][$option->option_name] = $option->option_value; 189 } 190 } 186 191 } 187 192 … … 189 194 $group_dir = $this->get_group_dir($group); 190 195 $make_dir = ''; 191 foreach ( split('/', $group_dir) as $subdir) {196 foreach (split('/', $group_dir) as $subdir) { 192 197 $make_dir .= "$subdir/"; 193 if (!file_exists($this->cache_dir .$make_dir)) {194 if (!mkdir($this->cache_dir .$make_dir))195 break;196 @ chmod($this->cache_dir .$make_dir, $perms);197 } 198 199 if (!file_exists($this->cache_dir . $make_dir ."index.php")) {200 touch($this->cache_dir . $make_dir ."index.php");201 } 202 } 203 204 return $this->cache_dir ."$group_dir/";198 if (!file_exists($this->cache_dir.$make_dir)) { 199 if (!mkdir($this->cache_dir.$make_dir)) 200 break; 201 @ chmod($this->cache_dir.$make_dir, $perms); 202 } 203 204 if (!file_exists($this->cache_dir.$make_dir."index.php")) { 205 touch($this->cache_dir.$make_dir."index.php"); 206 } 207 } 208 209 return $this->cache_dir."$group_dir/"; 205 210 } 206 211 207 212 function rm($fileglob) { 208 if (is_file($fileglob)) {209 return @unlink($fileglob);210 } else if (is_dir($fileglob)) { 211 $ok = $this->rm("$fileglob/*"); 212 if (! $ok) { 213 return false; 214 } 215 return @rmdir($fileglob);216 } else {217 $matching = glob($fileglob);218 if ($matching === false)219 return true;220 $rcs = array_map(array('WP_Object_Cache', 'rm'), $matching);221 if (in_array(false, $rcs)) {222 return false;223 }224 }225 return true;213 if (is_file($fileglob)) { 214 return @ unlink($fileglob); 215 } else 216 if (is_dir($fileglob)) { 217 $ok = WP_Object_Cache::rm("$fileglob/*"); 218 if (!$ok) 219 return false; 220 return @ rmdir($fileglob); 221 } else { 222 $matching = glob($fileglob); 223 if ($matching === false) 224 return true; 225 $rcs = array_map(array ('WP_Object_Cache', 'rm'), $matching); 226 if (in_array(false, $rcs)) { 227 return false; 228 } 229 } 230 return true; 226 231 } 227 232 228 233 function replace($id, $data, $group = 'default', $expire = '') { 229 if ( empty($group))230 $group = 'default'; 231 232 if ( false === $this->get($id, $group, false))234 if (empty ($group)) 235 $group = 'default'; 236 237 if (false === $this->get($id, $group, false)) 233 238 return false; 234 239 … … 237 242 238 243 function set($id, $data, $group = 'default', $expire = '') { 239 if ( empty($group))240 $group = 'default'; 241 242 if ( NULL == $data)244 if (empty ($group)) 245 $group = 'default'; 246 247 if (NULL == $data) 243 248 $data = ''; 244 249 245 250 $this->cache[$group][$id] = $data; 246 unset ($this->non_existant_objects[$group][$id]);251 unset ($this->non_existant_objects[$group][$id]); 247 252 $this->dirty_objects[$group][] = $id; 248 253 … … 269 274 @ chmod($this->cache_dir, $dir_perms); 270 275 } 271 272 if (!file_exists($this->cache_dir ."index.php")) {273 touch($this->cache_dir ."index.php");276 277 if (!file_exists($this->cache_dir."index.php")) { 278 touch($this->cache_dir."index.php"); 274 279 } 275 280 … … 291 296 $ids = array_unique($ids); 292 297 foreach ($ids as $id) { 293 $cache_file = $group_dir . md5($id . DB_PASSWORD) .'.php';298 $cache_file = $group_dir.md5($id.DB_PASSWORD).'.php'; 294 299 295 300 // Remove the cache file if the key is not set. 296 if ( ! isset($this->cache[$group][$id])) {297 if ( file_exists($cache_file))301 if (!isset ($this->cache[$group][$id])) { 302 if (file_exists($cache_file)) 298 303 unlink($cache_file); 299 304 continue; … … 301 306 302 307 $temp_file = tempnam($group_dir, 'tmp'); 303 $serial = CACHE_SERIAL_HEADER . serialize($this->cache[$group][$id]) .CACHE_SERIAL_FOOTER;308 $serial = CACHE_SERIAL_HEADER.serialize($this->cache[$group][$id]).CACHE_SERIAL_FOOTER; 304 309 $fd = fopen($temp_file, 'w'); 305 310 fputs($fd, $serial); 306 fclose($fd); 307 if (!@ rename($temp_file, $cache_file)) {308 if (copy ($temp_file, $cache_file)) {311 fclose($fd); 312 if (!@ rename($temp_file, $cache_file)) { 313 if (copy($temp_file, $cache_file)) { 309 314 unlink($temp_file); 310 315 } … … 334 339 print_r($cache); 335 340 echo "</pre>"; 336 if ( isset($this->dirty_objects[$group])) {341 if (isset ($this->dirty_objects[$group])) { 337 342 echo "<strong>Dirty Objects:</strong>"; 338 343 echo "<pre>"; … … 340 345 echo "</pre>"; 341 346 echo "</p>"; 342 } 347 } 343 348 } 344 349 } … … 347 352 global $blog_id; 348 353 349 if ( defined('DISABLE_CACHE'))354 if (defined('DISABLE_CACHE')) 350 355 return; 351 356 352 if ( defined('CACHE_PATH'))357 if (defined('CACHE_PATH')) 353 358 $this->cache_dir = CACHE_PATH; 354 359 else 355 360 $this->cache_dir = ABSPATH.'wp-content/cache/'; 356 361 357 if ( is_dir($this->cache_dir)) {358 if ( is_writable($this->cache_dir))362 if (is_dir($this->cache_dir)) { 363 if (is_writable($this->cache_dir)) 359 364 $this->cache_enabled = true; 360 } else if (is_writable(ABSPATH.'wp-content')) { 361 $this->cache_enabled = true; 362 } 363 364 if ( defined('CACHE_EXPIRATION_TIME') ) 365 } else 366 if (is_writable(ABSPATH.'wp-content')) { 367 $this->cache_enabled = true; 368 } 369 370 if (defined('CACHE_EXPIRATION_TIME')) 365 371 $this->expiration_time = CACHE_EXPIRATION_TIME; 366 372
