Changeset 3021
- Timestamp:
- 11/09/2005 11:10:34 AM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/cache.php
r3019 r3021 52 52 var $cache_dir; 53 53 var $cache_enabled = false; 54 var $expiration_time = 86400; 54 55 var $use_flock = false; 55 56 var $flock_filename = 'wp_object_cache.lock'; … … 58 59 var $cache = array (); 59 60 var $dirty_objects = array (); 61 var $non_existant_objects = array(); 60 62 var $global_groups = array('users', 'usermeta'); 61 63 var $blog_id; … … 68 70 $group = 'default'; 69 71 70 if ( isset ($this->cache[$group][$id]))72 if ( false !== $this->get($id, $group, false) ) 71 73 return false; 72 74 … … 78 80 $group = 'default'; 79 81 80 if ( !isset ($this->cache[$group][$id]))82 if ( false === $this->get($id, $group, false) ) 81 83 return false; 82 84 83 85 unset ($this->cache[$group][$id]); 86 $this->non_existant_objects[$group][$id] = true; 84 87 $this->dirty_objects[$group][] = $id; 85 88 return true; 86 89 } 87 90 88 function get($id, $group = 'default' ) {91 function get($id, $group = 'default', $count_hits = true) { 89 92 if ( empty($group) ) 90 93 $group = 'default'; 91 94 92 95 if (isset ($this->cache[$group][$id])) { 93 $this->warm_cache_hits += 1; 96 if ( $count_hits ) 97 $this->warm_cache_hits += 1; 94 98 return $this->cache[$group][$id]; 95 99 } 100 101 if ( isset($this->non_existant_objects[$group][$id]) ) 102 return false; 96 103 97 104 // If caching is not enabled, we have to fall back to pulling from the DB. … … 105 112 } 106 113 114 $this->non_existant_objects[$group][$id] = true; 107 115 $this->cache_misses += 1; 108 116 return false; … … 111 119 $cache_file = $this->cache_dir . $this->get_group_dir($group) . "/" . md5($id . DB_PASSWORD) . '.php'; 112 120 if (!file_exists($cache_file)) { 121 $this->non_existant_objects[$group][$id] = true; 113 122 $this->cache_misses += 1; 114 123 return false; 115 124 } 125 126 // If the object has expired, remove it from the cache and return false to force 127 // a refresh. 128 $now = time(); 129 if ( (filemtime($cache_file) + $this->expiration_time) <= $now ) { 130 $this->cache_misses += 1; 131 $this->delete($id, $group); 132 return false; 133 } 134 116 135 $this->cache[$group][$id] = unserialize(substr(@ file_get_contents($cache_file), strlen(CACHE_SERIAL_HEADER), -strlen(CACHE_SERIAL_FOOTER))); 117 136 if ( false === $this->cache[$group][$id]) 118 137 $this->cache[$group][$id] = ''; 138 119 139 $this->cold_cache_hits += 1; 120 140 return $this->cache[$group][$id]; … … 183 203 $group = 'default'; 184 204 185 if ( !isset ($this->cache[$group][$id]))205 if ( false === $this->get($id, $group, false) ) 186 206 return false; 187 207 … … 193 213 $group = 'default'; 194 214 215 if ( NULL == $data) 216 $data = ''; 217 195 218 $this->cache[$group][$id] = $data; 219 unset($this->non_existant_objects[$group][$id]); 196 220 $this->dirty_objects[$group][] = $id; 221 197 222 return true; 198 223 } 199 224 200 225 function save() { 201 226 //$this->stats(); … … 239 264 $ids = array_unique($ids); 240 265 foreach ($ids as $id) { 241 // TODO: If the id is no longer in the cache, it was deleted and242 // the file should be removed.243 266 $cache_file = $group_dir . md5($id . DB_PASSWORD) . '.php'; 267 268 // Remove the cache file if the key is not set. 269 if ( ! isset($this->cache[$group][$id]) ) { 270 echo "Deleting $group $id<br/>"; 271 if ( file_exists($cache_file) ) 272 unlink($cache_file); 273 continue; 274 } 275 244 276 $temp_file = tempnam($group_dir, 'tmp'); 245 277 $serial = CACHE_SERIAL_HEADER . serialize($this->cache[$group][$id]) . CACHE_SERIAL_FOOTER; … … 303 335 $this->cache_enabled = true; 304 336 } 305 337 338 if ( defined('CACHE_EXPIRATION_TIME') ) 339 $this->expiration_time = CACHE_EXPIRATION_TIME; 340 306 341 $this->blog_id = md5($blog_id); 307 342 }
Note: See TracChangeset
for help on using the changeset viewer.