Ticket #5511: cache.phpdoc.r6473.diff
File cache.phpdoc.r6473.diff, 11.7 KB (added by , 16 years ago) |
---|
-
cache.php
1 1 <?php 2 /** 3 * Object Cache API 4 * 5 * @package WordPress 6 * @subpackage Cache 7 */ 8 9 /** 10 * wp_cache_add() - {@internal Missing Short Description}} 11 * 12 * {@internal Missing Long Description}} 13 * 14 * @since 2.0 15 * @uses $wp_object_cache Object Cache Class 16 * 17 * @param unknown_type $key 18 * @param unknown_type $data 19 * @param unknown_type $flag 20 * @param unknown_type $expire 21 * @return unknown 22 */ 2 23 function wp_cache_add($key, $data, $flag = '', $expire = 0) { 3 24 global $wp_object_cache; 4 25 $data = unserialize(serialize($data)); … … 6 27 return $wp_object_cache->add($key, $data, $flag, $expire); 7 28 } 8 29 30 /** 31 * wp_cache_close() - {@internal Missing Short Description}} 32 * 33 * {@internal Missing Long Description}} 34 * 35 * @since 2.0 36 * @uses $wp_object_cache Object Cache Class 37 * 38 * @return unknown 39 */ 9 40 function wp_cache_close() { 10 41 global $wp_object_cache; 11 42 … … 14 45 return $wp_object_cache->save(); 15 46 } 16 47 48 /** 49 * wp_cache_delete() - {@internal Missing Short Description}} 50 * 51 * {@internal Missing Long Description}} 52 * 53 * @since 2.0 54 * @uses $wp_object_cache Object Cache Class 55 * 56 * @param unknown_type $id 57 * @param unknown_type $flag 58 * @return unknown 59 */ 17 60 function wp_cache_delete($id, $flag = '') { 18 61 global $wp_object_cache; 19 62 20 63 return $wp_object_cache->delete($id, $flag); 21 64 } 22 65 66 /** 67 * wp_cache_flush() - {@internal Missing Short Description}} 68 * 69 * {@internal Missing Long Description}} 70 * 71 * @since 2.0 72 * @uses $wp_object_cache Object Cache Class 73 * 74 * @return unknown 75 */ 23 76 function wp_cache_flush() { 24 77 global $wp_object_cache; 25 78 26 79 return $wp_object_cache->flush(); 27 80 } 28 81 82 /** 83 * wp_cache_get() - {@internal Missing Short Description}} 84 * 85 * {@internal Missing Long Description}} 86 * 87 * @since 2.0 88 * @uses $wp_object_cache Object Cache Class 89 * 90 * @param unknown_type $id 91 * @param unknown_type $flag 92 * @return unknown 93 */ 29 94 function wp_cache_get($id, $flag = '') { 30 95 global $wp_object_cache; 31 96 32 97 return $wp_object_cache->get($id, $flag); 33 98 } 34 99 100 /** 101 * wp_cache_init() - Sets up Object Cache Global and assigns it 102 * 103 * @since 2.0 104 * @global WP_Object_Cache $wp_object_cache WordPress Object Cache 105 */ 35 106 function wp_cache_init() { 36 107 $GLOBALS['wp_object_cache'] =& new WP_Object_Cache(); 37 108 } 38 109 110 /** 111 * wp_cache_replace() - {@internal Missing Short Description}} 112 * 113 * {@internal Missing Long Description}} 114 * 115 * @since 2.0 116 * @uses $wp_object_cache Object Cache Class 117 * 118 * @param unknown_type $key 119 * @param unknown_type $data 120 * @param unknown_type $flag 121 * @param unknown_type $expire 122 * @return unknown 123 */ 39 124 function wp_cache_replace($key, $data, $flag = '', $expire = 0) { 40 125 global $wp_object_cache; 41 126 $data = unserialize(serialize($data)); … … 43 128 return $wp_object_cache->replace($key, $data, $flag, $expire); 44 129 } 45 130 131 /** 132 * wp_cache_set() - {@internal Missing Short Description}} 133 * 134 * {@internal Missing Long Description}} 135 * 136 * @since 2.0 137 * @uses $wp_object_cache Object Cache Class 138 * 139 * @param unknown_type $key 140 * @param unknown_type $data 141 * @param unknown_type $flag 142 * @param unknown_type $expire 143 * @return unknown 144 */ 46 145 function wp_cache_set($key, $data, $flag = '', $expire = 0) { 47 146 global $wp_object_cache; 48 147 $data = unserialize(serialize($data)); … … 50 149 return $wp_object_cache->set($key, $data, $flag, $expire); 51 150 } 52 151 152 /** 153 * The cache file header 154 */ 53 155 define('CACHE_SERIAL_HEADER', "<?php\n/*"); 156 157 /** 158 * The cache file footer 159 */ 54 160 define('CACHE_SERIAL_FOOTER', "*/\n?".">"); 55 161 162 /** 163 * WordPress Object Cache 164 * 165 * {@internal Missing Long Description}} 166 * 167 * @package WordPress 168 * @subpackage Cache 169 * @since 2.0 170 */ 56 171 class WP_Object_Cache { 172 173 /** 174 * Cache Directory 175 * 176 * @var string 177 * @access public 178 */ 57 179 var $cache_dir; 180 181 /** 182 * Whether the cache is enabled 183 * 184 * @var bool 185 * @access public 186 */ 58 187 var $cache_enabled = false; 188 189 /** 190 * The expiration time of the cache files 191 * 192 * @var int 193 * @access public 194 */ 59 195 var $expiration_time = 900; 196 197 /** 198 * The filename of the 'flock' or file lock 199 * 200 * @var string 201 * @access public 202 */ 60 203 var $flock_filename = 'wp_object_cache.lock'; 204 205 /** 206 * The resource handle for the file lock 207 * 208 * @var resource 209 * @access private 210 */ 61 211 var $mutex; 212 213 /** 214 * Holds the cached objects 215 * 216 * @var array 217 * @access private 218 */ 62 219 var $cache = array (); 220 221 /** 222 * Objects in cache that have become "dirty" 223 * 224 * "Dirty" refers to an cache that has since been updated 225 * in the "live" environment, but had not yet cleared the 226 * cache referring to that update. 227 * 228 * @var array 229 * @access private 230 */ 63 231 var $dirty_objects = array (); 232 233 /** 234 * {@internal Missing Description}} 235 * 236 * @var array 237 * @access private 238 */ 64 239 var $non_existant_objects = array (); 240 241 /** 242 * Object caches that are global 243 * 244 * @var array 245 * @access private 246 */ 65 247 var $global_groups = array ('users', 'userlogins', 'usermeta'); 248 249 /** 250 * Object caches that don't persist 251 * 252 * @var array 253 * @access private 254 */ 66 255 var $non_persistent_groups = array('comment'); 256 257 /** 258 * Holds the blog id that the object cache refers to 259 * 260 * @var int 261 * @access public 262 */ 67 263 var $blog_id; 264 265 /** 266 * {@internal Missing Description}} 267 * 268 * @var int 269 * @access public 270 */ 68 271 var $cold_cache_hits = 0; 272 273 /** 274 * {@internal Missing Description}} 275 * 276 * @var int 277 * @access public 278 */ 69 279 var $warm_cache_hits = 0; 280 281 /** 282 * {@internal Missing Description}} 283 * 284 * @var int 285 */ 70 286 var $cache_misses = 0; 287 288 /** 289 * {@internal Missing Description}} 290 * 291 * @var string 292 */ 71 293 var $secret = ''; 72 294 295 /** 296 * Creates a mutex to attempt a lock on a cached file. 297 * 298 * The lock will be attempted to be preformed on cached files 299 * to prevent collisions between multiple caches/access attempts. 300 * 301 * @since 2.0.1 302 * 303 * @return bool Whether the lock could be acquired 304 */ 73 305 function acquire_lock() { 74 306 // Acquire a write lock. 75 307 $this->mutex = @fopen($this->cache_dir.$this->flock_filename, 'w'); … … 79 311 return true; 80 312 } 81 313 314 /** 315 * {@internal Missing Short Description}} 316 * 317 * {@internal Missing Long Description}} 318 * 319 * @since unknown 320 * 321 * @param unknown_type $id {@internal Missing Description}} 322 * @param unknown_type $data {@internal Missing Description}} 323 * @param unknown_type $group {@internal Missing Description}} 324 * @param unknown_type $expire {@internal Missing Description}} 325 * @return bool|unknown {@internal Missing Description}} 326 */ 82 327 function add($id, $data, $group = 'default', $expire = '') { 83 328 if (empty ($group)) 84 329 $group = 'default'; … … 89 334 return $this->set($id, $data, $group, $expire); 90 335 } 91 336 337 /** 338 * {@internal Missing Short Description}} 339 * 340 * {@internal Missing Long Description}} 341 * 342 * @since unknown 343 * 344 * @param unknown_type $id 345 * @param unknown_type $group 346 * @param unknown_type $force 347 * @return unknown 348 */ 92 349 function delete($id, $group = 'default', $force = false) { 93 350 if (empty ($group)) 94 351 $group = 'default'; … … 102 359 return true; 103 360 } 104 361 362 /** 363 * {@internal Missing Short Description}} 364 * 365 * {@internal Missing Long Description}} 366 * 367 * @since unknown 368 * 369 * @return unknown 370 */ 105 371 function flush() { 106 372 if ( !$this->cache_enabled ) 107 373 return true; … … 119 385 return true; 120 386 } 121 387 388 /** 389 * {@internal Missing Short Description}} 390 * 391 * {@internal Missing Long Description}} 392 * 393 * @since unknown 394 * 395 * @param unknown_type $id 396 * @param unknown_type $group 397 * @param unknown_type $count_hits 398 * @return unknown 399 */ 122 400 function get($id, $group = 'default', $count_hits = true) { 123 401 if (empty ($group)) 124 402 $group = 'default'; … … 171 449 return $this->cache[$group][$id]; 172 450 } 173 451 452 /** 453 * {@internal Missing Short Description}} 454 * 455 * {@internal Missing Long Description}} 456 * 457 * @since unknown 458 * 459 * @param unknown_type $group 460 * @return unknown 461 */ 174 462 function get_group_dir($group) { 175 463 if (false !== array_search($group, $this->global_groups)) 176 464 return $group; … … 178 466 return "{$this->blog_id}/$group"; 179 467 } 180 468 469 /** 470 * {@internal Missing Short Description}} 471 * 472 * {@internal Missing Long Description}} 473 * 474 * @since unknown 475 * 476 * @param unknown_type $data 477 * @return unknown 478 */ 181 479 function hash($data) { 182 480 if ( function_exists('hash_hmac') ) { 183 481 return hash_hmac('md5', $data, $this->secret); … … 186 484 } 187 485 } 188 486 487 /** 488 * {@internal Missing Short Description}} 489 * 490 * {@internal Missing Long Description}} 491 * 492 * @since unknown 493 * 494 * @param unknown_type $group 495 */ 189 496 function load_group_from_db($group) { 190 497 return; 191 498 } 192 499 500 /** 501 * {@internal Missing Short Description}} 502 * 503 * {@internal Missing Long Description}} 504 * 505 * @since unknown 506 * 507 * @param unknown_type $group 508 * @param unknown_type $perms 509 * @return unknown 510 */ 193 511 function make_group_dir($group, $perms) { 194 512 $group_dir = $this->get_group_dir($group); 195 513 $make_dir = ''; … … 211 529 return $this->cache_dir."$group_dir/"; 212 530 } 213 531 532 /** 533 * {@internal Missing Short Description}} 534 * 535 * {@internal Missing Long Description}} 536 * 537 * @since unknown 538 * 539 * @return unknown 540 */ 214 541 function rm_cache_dir() { 215 542 $dir = $this->cache_dir; 216 543 $dir = rtrim($dir, DIRECTORY_SEPARATOR); … … 247 574 248 575 } 249 576 577 /** 578 * {@internal Missing Short Description}} 579 * 580 * {@internal Missing Long Description}} 581 * 582 * @since unknown 583 * 584 */ 250 585 function release_lock() { 251 586 // Release write lock. 252 587 flock($this->mutex, LOCK_UN); 253 588 fclose($this->mutex); 254 589 } 255 590 591 /** 592 * {@internal Missing Short Description}} 593 * 594 * {@internal Missing Long Description}} 595 * 596 * @since unknown 597 * 598 * @param unknown_type $id 599 * @param unknown_type $data 600 * @param unknown_type $group 601 * @param unknown_type $expire 602 * @return unknown 603 */ 256 604 function replace($id, $data, $group = 'default', $expire = '') { 257 605 if (empty ($group)) 258 606 $group = 'default'; … … 263 611 return $this->set($id, $data, $group, $expire); 264 612 } 265 613 614 /** 615 * {@internal Missing Short Description}} 616 * 617 * {@internal Missing Long Description}} 618 * 619 * @since unknown 620 * 621 * @param unknown_type $id 622 * @param unknown_type $data 623 * @param unknown_type $group 624 * @param unknown_type $expire 625 * @return unknown 626 */ 266 627 function set($id, $data, $group = 'default', $expire = '') { 267 628 if (empty ($group)) 268 629 $group = 'default'; … … 277 638 return true; 278 639 } 279 640 641 /** 642 * {@internal Missing Short Description}} 643 * 644 * {@internal Missing Long Description}} 645 * 646 * @since unknown 647 * 648 * @return unknown 649 */ 280 650 function save() { 281 651 //$this->stats(); 282 652 … … 353 723 return true; 354 724 } 355 725 726 /** 727 * {@internal Missing Short Description}} 728 * 729 * {@internal Missing Long Description}} 730 * 731 * @since unknown 732 */ 356 733 function stats() { 357 734 echo "<p>"; 358 735 echo "<strong>Cold Cache Hits:</strong> {$this->cold_cache_hits}<br />"; … … 377 754 } 378 755 } 379 756 757 /** 758 * Calls PHP 5 style constructor and sets up PHP 4 destructor 759 * 760 * @since 2.0 761 * 762 * @return WP_Object_Cache 763 */ 380 764 function WP_Object_Cache() { 381 765 return $this->__construct(); 382 766 } 383 767 768 /** 769 * Sets up object properties 770 * 771 * @since unknown 772 */ 384 773 function __construct() { 385 774 global $blog_id; 386 775 … … 421 810 $this->blog_id = $this->hash($blog_id); 422 811 } 423 812 813 /** 814 * Will save the object cache before object is completely destroyed. 815 * 816 * Called upon object destruction, which should be when PHP ends. 817 * 818 * @return bool Won't be used by PHP 819 */ 424 820 function __destruct() { 425 821 $this->save(); 426 822 return true;