Ticket #4179: 4179.cache.expire.2.patch
| File 4179.cache.expire.2.patch, 3.7 KB (added by DD32, 6 years ago) |
|---|
-
wp-includes/cache.php
1 1 <?php 2 function wp_cache_add($key, $data, $flag = '', $expire = 0) {2 function wp_cache_add($key, $data, $flag = '', $expire = '') { 3 3 global $wp_object_cache; 4 4 $data = unserialize(serialize($data)); 5 5 … … 36 36 $GLOBALS['wp_object_cache'] =& new WP_Object_Cache(); 37 37 } 38 38 39 function wp_cache_replace($key, $data, $flag = '', $expire = 0) {39 function wp_cache_replace($key, $data, $flag = '', $expire = '') { 40 40 global $wp_object_cache; 41 41 $data = unserialize(serialize($data)); 42 42 43 43 return $wp_object_cache->replace($key, $data, $flag, $expire); 44 44 } 45 45 46 function wp_cache_set($key, $data, $flag = '', $expire = 0) {46 function wp_cache_set($key, $data, $flag = '', $expire = '') { 47 47 global $wp_object_cache; 48 48 $data = unserialize(serialize($data)); 49 49 … … 57 57 var $cache_dir; 58 58 var $cache_enabled = false; 59 59 var $expiration_time = 900; 60 var $expire_in = array(); 60 61 var $flock_filename = 'wp_object_cache.lock'; 61 62 var $mutex; 62 63 var $cache = array (); … … 146 147 return false; 147 148 } 148 149 149 $cache_file = $this->cache_dir .$this->get_group_dir($group)."/".$this->hash($id).'.php';150 $cache_file = $this->cache_dir . $this->get_group_dir($group) . DIRECTORY_SEPARATOR . $this->hash($id) . '.php'; 150 151 if (!file_exists($cache_file)) { 151 152 $this->non_existant_objects[$group][$id] = true; 152 153 $this->cache_misses += 1; … … 155 156 156 157 // If the object has expired, remove it from the cache and return false to force 157 158 // a refresh. 158 $now = time(); 159 if ((filemtime($cache_file) + $this->expiration_time) <= $now) { 159 if ( filemtime($cache_file) <= time() ) { 160 160 $this->cache_misses += 1; 161 161 $this->delete($id, $group, true); 162 162 return false; … … 174 174 if (false !== array_search($group, $this->global_groups)) 175 175 return $group; 176 176 177 return "{$this->blog_id}/$group";177 return $this->blog_id . DIRECTORY_SEPARATOR . $group; 178 178 } 179 179 180 180 function hash($data) { … … 201 201 function make_group_dir($group, $perms) { 202 202 $group_dir = $this->get_group_dir($group); 203 203 $make_dir = ''; 204 foreach ( split('/', $group_dir) as $subdir) {205 $make_dir .= "$subdir/";204 foreach (explode(DIRECTORY_SEPARATOR, $group_dir) as $subdir) { 205 $make_dir .= $subdir . DIRECTORY_SEPARATOR; 206 206 if (!file_exists($this->cache_dir.$make_dir)) { 207 207 if (! @ mkdir($this->cache_dir.$make_dir)) 208 208 break; … … 216 216 } 217 217 } 218 218 219 return $this->cache_dir ."$group_dir/";219 return $this->cache_dir . $group_dir . DIRECTORY_SEPARATOR; 220 220 } 221 221 222 222 function rm_cache_dir() { … … 275 275 if (empty ($group)) 276 276 $group = 'default'; 277 277 278 if( empty($expire) ) 279 $expire = $this->expiration_time; 280 278 281 if (NULL == $data) 279 282 $data = ''; 280 283 281 284 $this->cache[$group][$id] = $data; 282 285 unset ($this->non_existant_objects[$group][$id]); 283 286 $this->dirty_objects[$group][] = $id; 287 $this->expire_in[$group][$id] = $expire; 284 288 285 289 return true; 286 290 } … … 345 349 @ unlink($temp_file); 346 350 } 347 351 @ chmod($cache_file, $file_perms); 352 @ touch($cache_file, time() + $this->expire_in[$group][$id] ); 348 353 } 349 354 } 350 355 … … 377 382 echo "<pre>"; 378 383 print_r(array_unique($this->dirty_objects[$group])); 379 384 echo "</pre>"; 380 echo "</p>";381 385 } 386 echo "</p>"; 382 387 } 383 388 } 384 389 … … 401 406 if ( ini_get('safe_mode') && ! defined('ENABLE_CACHE') ) 402 407 return; 403 408 409 if ( ! defined( 'DIRECTORY_SEPARATOR' ) ) { 410 if ( strpos( $_ENV[ 'OS' ], 'Win' ) !== false ) 411 define( 'DIRECTORY_SEPARATOR', '\\' ); 412 else 413 define( 'DIRECTORY_SEPARATOR', '/' ); 414 } 415 404 416 if (defined('CACHE_PATH')) 405 417 $this->cache_dir = CACHE_PATH; 406 418 else
