WP Super Cache - Version 0.8.7

Version Description

Download this release

Release Info

Developer donncha
Plugin Icon 128x128 WP Super Cache
Version 0.8.7
Comparing to
See all releases

Code changes from version 0.8.6 to 0.8.7

Files changed (4) hide show
  1. Changelog.txt +21 -0
  2. readme.txt +1 -1
  3. wp-cache-phase2.php +39 -14
  4. wp-cache.php +9 -8
Changelog.txt CHANGED
@@ -1,3 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  2008-12-04 18:12 donncha
2
 
3
  * wp-cache-phase1.php: Added "WP-Super-Cache: WP-Cache" header for
1
+ 2009-01-09 11:04 donncha
2
+
3
+ * readme.txt, wp-cache.php: Bump version to 0.8.7
4
+
5
+ 2009-01-09 10:59 donncha
6
+
7
+ * wp-cache-phase2.php, wp-cache.php: Change default expiry time to
8
+ 10 minutes
9
+ Only clean out 100 files at a time. Should help with very large
10
+ sites.
11
+ Fix file pointer.
12
+
13
+ 2008-12-05 09:57 donncha
14
+
15
+ * wp-cache.php: Fix term -> meta typo, props kettari,
16
+ http://wordpress.org/support/topic/222613?replies=1
17
+
18
+ 2008-12-04 18:13 donncha
19
+
20
+ * Changelog.txt: Updated changelog for 0.8.6
21
+
22
  2008-12-04 18:12 donncha
23
 
24
  * wp-cache-phase1.php: Added "WP-Super-Cache: WP-Cache" header for
readme.txt CHANGED
@@ -2,7 +2,7 @@
2
  Contributors: donncha
3
  Tags: performance,caching,wp-cache,wp-super-cache
4
  Tested up to: 2.7
5
- Stable tag: 0.8.6
6
  Requires at least: 2.2
7
 
8
  A very fast caching engine for WordPress that produces static html files.
2
  Contributors: donncha
3
  Tags: performance,caching,wp-cache,wp-super-cache
4
  Tested up to: 2.7
5
+ Stable tag: 0.8.7
6
  Requires at least: 2.2
7
 
8
  A very fast caching engine for WordPress that produces static html files.
wp-cache-phase2.php CHANGED
@@ -224,7 +224,7 @@ function wp_cache_ob_callback($buffer) {
224
  $fr2 = @fopen( $tmp_cache_filename, 'w' );
225
  if (!$fr2) {
226
  $buffer .= "<!-- File not cached! Super Cache Couldn't write to: " . str_replace( ABSPATH, '', $tmp_cache_filename ) . " -->\n";
227
- fclose( $fp );
228
  unlink( $tmp_wpcache_filename );
229
  return $buffer;
230
  }
@@ -232,9 +232,9 @@ function wp_cache_ob_callback($buffer) {
232
  $gz = @fopen( $tmp_cache_filename . ".gz", 'w');
233
  if (!$gz) {
234
  $buffer .= "<!-- File not cached! Super Cache Couldn't write to: " . str_replace( ABSPATH, '', $tmp_cache_filename ) . ".gz -->\n";
235
- fclose( $fp );
236
  unlink( $tmp_wpcache_filename );
237
- fclose( $fp2 );
238
  unlink( $tmp_cache_filename );
239
  return $buffer;
240
  }
@@ -322,8 +322,21 @@ function wp_cache_phase2_clean_cache($file_prefix) {
322
  wp_cache_writers_exit();
323
  }
324
 
325
- function prune_super_cache($directory, $force = false, $rename = false) {
 
 
 
 
 
 
 
 
 
 
 
 
326
  global $cache_max_time, $cache_path, $super_cache_enabled, $cache_rebuild_files;
 
327
 
328
  if( !is_admin() && $super_cache_enabled == 0 )
329
  return false;
@@ -341,13 +354,21 @@ function prune_super_cache($directory, $force = false, $rename = false) {
341
  $entries = glob($directory. '*');
342
  if( is_array( $entries ) && !empty( $entries ) ) foreach ($entries as $entry) {
343
  if ($entry != '.' && $entry != '..') {
344
- prune_super_cache( $entry, $force, $rename );
345
- if( is_dir( $entry ) && ( $force || @filemtime( $entry ) + $cache_max_time <= $now ) ) {
346
- $oktodelete = true;
347
- if( in_array( $entry, $protected_directories ) )
348
- $oktodelete = false;
349
- if( $oktodelete && !$rename )
 
 
 
 
 
 
350
  @rmdir( $entry );
 
 
351
  }
352
  }
353
  }
@@ -357,12 +378,16 @@ function prune_super_cache($directory, $force = false, $rename = false) {
357
  $oktodelete = false;
358
  if( $oktodelete && !$rename ) {
359
  @unlink( $directory );
 
360
  } elseif( $oktodelete && $rename ) {
361
  if( $cache_rebuild_files && substr( $directory, -14 ) != '.needs-rebuild' ) {
362
- if( @rename($directory, $directory . '.needs-rebuild') )
363
  @touch( $directory . '.needs-rebuild' );
 
 
364
  } else {
365
  @unlink( $directory );
 
366
  }
367
 
368
  }
@@ -483,7 +508,7 @@ function wp_cache_shutdown_callback() {
483
  }
484
 
485
  if( !isset( $wp_cache_gc ) )
486
- $wp_cache_gc = 3600;
487
  $last_gc = get_option( "wpsupercache_gc_time" );
488
 
489
  if( !$last_gc ) {
@@ -605,10 +630,10 @@ function wp_cache_gc_cron() {
605
  global $file_prefix, $wp_cache_gc;
606
 
607
  if( !isset( $wp_cache_gc ) )
608
- $wp_cache_gc = 3600;
609
 
610
  if( !wp_cache_phase2_clean_expired($file_prefix ) )
611
- update_option( 'wpsupercache_gc_time', time() - ( $wp_cache_gc - 600 ) ); // if GC failed then run it again in 10 minutes
612
  }
613
 
614
  ?>
224
  $fr2 = @fopen( $tmp_cache_filename, 'w' );
225
  if (!$fr2) {
226
  $buffer .= "<!-- File not cached! Super Cache Couldn't write to: " . str_replace( ABSPATH, '', $tmp_cache_filename ) . " -->\n";
227
+ fclose( $fr );
228
  unlink( $tmp_wpcache_filename );
229
  return $buffer;
230
  }
232
  $gz = @fopen( $tmp_cache_filename . ".gz", 'w');
233
  if (!$gz) {
234
  $buffer .= "<!-- File not cached! Super Cache Couldn't write to: " . str_replace( ABSPATH, '', $tmp_cache_filename ) . ".gz -->\n";
235
+ fclose( $fr );
236
  unlink( $tmp_wpcache_filename );
237
+ fclose( $fr2 );
238
  unlink( $tmp_cache_filename );
239
  return $buffer;
240
  }
322
  wp_cache_writers_exit();
323
  }
324
 
325
+ function prune_super_cache( $directory, $force = false, $rename = false ) {
326
+ global $gc_file_counter;
327
+ $c = 0;
328
+ while( $c < 20 && is_dir( $directory ) ) {
329
+ $gc_file_counter = 0;
330
+ sc_garbage_collection( $directory, $force, $rename );
331
+ $c++;
332
+ if( $gc_file_counter == 0 )
333
+ $c = 20;
334
+ }
335
+ }
336
+
337
+ function sc_garbage_collection( $directory, $force = false, $rename = false ) {
338
  global $cache_max_time, $cache_path, $super_cache_enabled, $cache_rebuild_files;
339
+ global $gc_file_counter;
340
 
341
  if( !is_admin() && $super_cache_enabled == 0 )
342
  return false;
354
  $entries = glob($directory. '*');
355
  if( is_array( $entries ) && !empty( $entries ) ) foreach ($entries as $entry) {
356
  if ($entry != '.' && $entry != '..') {
357
+ if( $gc_file_counter < 100 ) {
358
+ sc_garbage_collection( $entry, $force, $rename );
359
+ }
360
+ // If entry is a directory, AND it's not a protected one, AND we're either forcing the delete, OR the file is out of date,
361
+ if( is_dir( $entry ) &&
362
+ !in_array( $entry, $protected_directories ) &&
363
+ ( $force || @filemtime( $entry ) + $cache_max_time <= $now ) ) {
364
+ // if the directory isn't empty can't delete it
365
+ if( is_array( glob($entry. '/*') ) ) {
366
+ continue;
367
+ }
368
+ if( !$rename ) {
369
  @rmdir( $entry );
370
+ $gc_file_counter++;
371
+ }
372
  }
373
  }
374
  }
378
  $oktodelete = false;
379
  if( $oktodelete && !$rename ) {
380
  @unlink( $directory );
381
+ $gc_file_counter++;
382
  } elseif( $oktodelete && $rename ) {
383
  if( $cache_rebuild_files && substr( $directory, -14 ) != '.needs-rebuild' ) {
384
+ if( @rename($directory, $directory . '.needs-rebuild') ) {
385
  @touch( $directory . '.needs-rebuild' );
386
+ $gc_file_counter++;
387
+ }
388
  } else {
389
  @unlink( $directory );
390
+ $gc_file_counter++;
391
  }
392
 
393
  }
508
  }
509
 
510
  if( !isset( $wp_cache_gc ) )
511
+ $wp_cache_gc = 600;
512
  $last_gc = get_option( "wpsupercache_gc_time" );
513
 
514
  if( !$last_gc ) {
630
  global $file_prefix, $wp_cache_gc;
631
 
632
  if( !isset( $wp_cache_gc ) )
633
+ $wp_cache_gc = 600;
634
 
635
  if( !wp_cache_phase2_clean_expired($file_prefix ) )
636
+ update_option( 'wpsupercache_gc_time', time() - ( $wp_cache_gc - 300 ) ); // if GC failed then run it again in 5 minutes
637
  }
638
 
639
  ?>
wp-cache.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: WP Super Cache
4
  Plugin URI: http://ocaoimh.ie/wp-super-cache/
5
  Description: Very fast caching module for WordPress. Once activated, you must <a href="options-general.php?page=wpsupercache">enable the cache</a>.
6
- Version: 0.8.6
7
  Author: Donncha O Caoimh
8
  Author URI: http://ocaoimh.ie/
9
  */
@@ -661,15 +661,16 @@ function wp_cache_edit_max_time () {
661
  echo '<label for="wp_max_time">Expire time:</label> ';
662
  echo "<input type=\"text\" size=6 name=\"wp_max_time\" value=\"$cache_max_time\" /> seconds<br />";
663
  if( !isset( $wp_cache_gc ) ) {
664
- $wp_cache_gc = 3600;
665
- } elseif( $wp_cache_gc != '3600' && $wp_cache_gc != '21600' && $wp_cache_gc != '86400' ) {
666
- $wp_cache_gc = '3600';
667
  }
668
  echo "<h4>Garbage Collection</h4><p>How often should expired files be deleted?</p>";
669
- echo "<ul><li><input type='radio' name='wp_cache_gc' value='3600'" . ( $wp_cache_gc == 3600 ? ' checked=checked' : '' ) . " /> Once every hour.</li>\n";
 
670
  echo "<li><input type='radio' name='wp_cache_gc' value='21600'" . ( $wp_cache_gc == 21600 ? ' checked=checked' : '' ) . " /> Once every 6 hours. </li>\n";
671
  echo "<li><input type='radio' name='wp_cache_gc' value='86400'" . ( $wp_cache_gc == 86400 ? ' checked=checked' : '' ) . " /> Once every 24 hours.</li></ul>\n";
672
- echo "<p>Checking for and deleting expired files is expensive, but it's expensive leaving them there too. On a very busy site you can leave this fairly high. Experiment with different values and visit this page to see how many expired files remain at different times during the day.</p>";
673
  echo '<div><input type="submit" ' . SUBMITDISABLED . 'value="Change expiration &raquo;" /></div>';
674
  wp_nonce_field('wp-cache');
675
  echo "</form>\n";
@@ -1177,7 +1178,7 @@ function wp_cache_clean_cache($file_prefix) {
1177
  while ( false !== ($file = readdir($handle))) {
1178
  if ( preg_match($expr, $file) ) {
1179
  @unlink($cache_path . $file);
1180
- @unlink($cache_path . 'meta/' . str_replace( '.html', '.term', $file ) );
1181
  }
1182
  }
1183
  closedir($handle);
@@ -1208,7 +1209,7 @@ function wp_cache_clean_expired($file_prefix) {
1208
  if ( preg_match($expr, $file) &&
1209
  (filemtime($cache_path . $file) + $cache_max_time) <= $now) {
1210
  unlink($cache_path . $file);
1211
- unlink($cache_path . 'meta/' . str_replace( '.html', '.term', $file ) );
1212
  }
1213
  }
1214
  closedir($handle);
3
  Plugin Name: WP Super Cache
4
  Plugin URI: http://ocaoimh.ie/wp-super-cache/
5
  Description: Very fast caching module for WordPress. Once activated, you must <a href="options-general.php?page=wpsupercache">enable the cache</a>.
6
+ Version: 0.8.7
7
  Author: Donncha O Caoimh
8
  Author URI: http://ocaoimh.ie/
9
  */
661
  echo '<label for="wp_max_time">Expire time:</label> ';
662
  echo "<input type=\"text\" size=6 name=\"wp_max_time\" value=\"$cache_max_time\" /> seconds<br />";
663
  if( !isset( $wp_cache_gc ) ) {
664
+ $wp_cache_gc = 600;
665
+ } elseif( $wp_cache_gc != 600 && $wp_cache_gc != '3600' && $wp_cache_gc != '21600' && $wp_cache_gc != '86400' ) {
666
+ $wp_cache_gc = '600';
667
  }
668
  echo "<h4>Garbage Collection</h4><p>How often should expired files be deleted?</p>";
669
+ echo "<ul><li><input type='radio' name='wp_cache_gc' value='600'" . ( $wp_cache_gc == 600 ? ' checked=checked' : '' ) . " /> Once every 10 minutes.</li>\n";
670
+ echo "<li><input type='radio' name='wp_cache_gc' value='3600'" . ( $wp_cache_gc == 3600 ? ' checked=checked' : '' ) . " /> Once every hour.</li>\n";
671
  echo "<li><input type='radio' name='wp_cache_gc' value='21600'" . ( $wp_cache_gc == 21600 ? ' checked=checked' : '' ) . " /> Once every 6 hours. </li>\n";
672
  echo "<li><input type='radio' name='wp_cache_gc' value='86400'" . ( $wp_cache_gc == 86400 ? ' checked=checked' : '' ) . " /> Once every 24 hours.</li></ul>\n";
673
+ echo "<p>Checking for and deleting expired files is expensive, but it's expensive leaving them there too. On a very busy site you should set this to <em>10 minutes</em>. Experiment with different values and visit this page to see how many expired files remain at different times during the day.</p>";
674
  echo '<div><input type="submit" ' . SUBMITDISABLED . 'value="Change expiration &raquo;" /></div>';
675
  wp_nonce_field('wp-cache');
676
  echo "</form>\n";
1178
  while ( false !== ($file = readdir($handle))) {
1179
  if ( preg_match($expr, $file) ) {
1180
  @unlink($cache_path . $file);
1181
+ @unlink($cache_path . 'meta/' . str_replace( '.html', '.meta', $file ) );
1182
  }
1183
  }
1184
  closedir($handle);
1209
  if ( preg_match($expr, $file) &&
1210
  (filemtime($cache_path . $file) + $cache_max_time) <= $now) {
1211
  unlink($cache_path . $file);
1212
+ unlink($cache_path . 'meta/' . str_replace( '.html', '.meta', $file ) );
1213
  }
1214
  }
1215
  closedir($handle);