Changeset 3030898
- Timestamp:
- 02/03/2024 03:00:15 PM (2 years ago)
- Location:
- surge/trunk
- Files:
-
- 7 edited
-
include/cache.php (modified) (6 diffs)
-
include/common.php (modified) (2 diffs)
-
include/cron.php (modified) (1 diff)
-
include/invalidate.php (modified) (3 diffs)
-
include/serve.php (modified) (2 diffs)
-
readme.txt (modified) (2 diffs)
-
surge.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
surge/trunk/include/cache.php
r2846380 r3030898 10 10 11 11 namespace Surge; 12 13 if ( defined( 'DOING_CRON' ) && DOING_CRON ) { 14 return; 15 } 12 16 13 17 include_once( __DIR__ . '/common.php' ); … … 24 28 25 29 if ( $ttl < 1 ) { 30 header( 'X-Cache: bypass' ); 26 31 return $contents; 27 32 } … … 70 75 71 76 if ( $skip ) { 77 header( 'X-Cache: bypass' ); 72 78 return $contents; 73 79 } … … 84 90 ]; 85 91 86 $meta = json_encode( $meta );92 $meta_json = json_encode( $meta ); 87 93 $cache_key = md5( json_encode( $key ) ); 88 94 $level = substr( $cache_key, -2 ); … … 98 104 // Could not create file. 99 105 if ( false === $f ) { 106 header( 'X-Cache: bypass' ); 100 107 return $contents; 101 108 } 102 109 103 110 fwrite( $f, '<?php exit; ?>' ); 104 fwrite( $f, pack( 'L', strlen( $meta ) ) );105 fwrite( $f, $meta );111 fwrite( $f, pack( 'L', strlen( $meta_json ) ) ); 112 fwrite( $f, $meta_json ); 106 113 fwrite( $f, $contents ); 107 114 … … 116 123 } 117 124 125 event( 'request', [ 'meta' => $meta ] ); 118 126 return $contents; 119 127 }; -
surge/trunk/include/common.php
r2846380 r3030898 49 49 // Add items to this array to add a unique cache variant. 50 50 'variants' => [], 51 52 // Add callbacks to events early to do crazy stuff. 53 'events' => [], 51 54 ]; 52 55 … … 246 249 return true; 247 250 } 251 252 /** 253 * Execute an event. 254 * 255 * @param string $event The event name. 256 * @param array $args An array for arguments to pass to callbacks. 257 */ 258 function event( $event, $args ) { 259 $events = config( 'events' ); 260 261 if ( empty( $events[ $event ] ) ) { 262 return; 263 } 264 265 foreach ( $events[ $event ] as $key => $callback ) { 266 $callback( $args ); 267 } 268 } -
surge/trunk/include/cron.php
r2711432 r3030898 48 48 foreach ( $files as $filename ) { 49 49 // Some files after scandir may already be gone/renamed. 50 if ( ! file_exists( $filename ) ) { 51 continue; 52 } 53 50 54 $stat = @stat( $filename ); 51 55 if ( ! $stat ) { -
surge/trunk/include/invalidate.php
r2846380 r3030898 98 98 expire( sprintf( 'post:%d:%d', $blog_id, $post_id ) ); 99 99 }, 10, 2 ); 100 101 // Multisite network/blog flags. 102 add_action( 'init', function() { 103 if ( is_multisite() ) { 104 flag( sprintf( 'network:%d:%d', get_current_network_id(), get_current_blog_id() ) ); 105 } 106 } ); 100 107 101 108 // Last-minute expirations, save flags. … … 118 125 'update_option_posts_per_page', 119 126 'update_option_woocommerce_permalinks', 127 ]; 128 129 $flush_actions = apply_filters( 'surge_flush_actions', $flush_actions ); 130 131 $ms_flush_actions = [ 132 '_core_updated_successfully', 120 133 'automatic_updates_complete', 121 '_core_updated_successfully',122 134 ]; 123 135 136 $expire_flag = is_multisite() 137 ? sprintf( 'network:%d:%d', get_current_network_id(), get_current_blog_id() ) 138 : '/'; 139 124 140 foreach ( $flush_actions as $action ) { 141 if ( did_action( $action ) ) { 142 expire( $expire_flag ); 143 break; 144 } 145 } 146 147 // Multisite flush actions expire the entire network. 148 foreach ( $ms_flush_actions as $action ) { 125 149 if ( did_action( $action ) ) { 126 150 expire( '/' ); … … 174 198 fwrite( $f, '<?php exit; ?>' . json_encode( $flags ) ); 175 199 fclose( $f ); 200 201 event( 'expire', [ 'flags' => $expire ] ); 176 202 } ); 177 203 -
surge/trunk/include/serve.php
r2674872 r3030898 53 53 // Invalidate by path. 54 54 if ( substr( $flag, 0, 1 ) == '/' ) { 55 if ( substr( $meta['path'], 0, strlen( $flag ) ) ) {55 if ( substr( $meta['path'], 0, strlen( $flag ) ) === $flag ) { 56 56 header( 'X-Cache: expired' ); 57 57 fclose( $f ); … … 81 81 82 82 header( 'X-Cache: hit' ); 83 // header( 'X-Flags: ' . implode( ', ', $meta['flags'] ));83 event( 'request', [ 'meta' => $meta ] ); 84 84 fpassthru( $f ); // Pass the remaining bytes to the output. 85 85 fclose( $f ); -
surge/trunk/readme.txt
r2968909 r3030898 4 4 Tags: cache, performance, caching 5 5 Requires at least: 5.7 6 Tested up to: 6. 36 Tested up to: 6.4 7 7 Requires PHP: 7.3 8 Stable tag: 1. 0.58 Stable tag: 1.1.0 9 9 License: GPLv3 or later 10 10 License URI: https://www.gnu.org/licenses/gpl-3.0.en.html … … 67 67 == Changelog == 68 68 69 = 1.1.0 = 70 * Improved Multisite compatibility 71 * Fixed occasional stat() warnings in cleanup routines 72 * Fixed expiration by path being too broad 73 * Added a filter for flush actions 74 * Feature: added a simple events system for s-maxage and stale-while-revalidate support 75 69 76 = 1.0.5 = 70 77 * Fix woocommerce_product_title compatibility -
surge/trunk/surge.php
r2846380 r3030898 51 51 } ); 52 52 53 // Support for 6.1+ cache headers check. 54 add_filter( 'site_status_page_cache_supported_cache_headers', function( $headers ) { 55 $headers['x-cache'] = static function( $value ) { 56 return false !== strpos( strtolower( $value ), 'hit' ); 57 }; 58 return $headers; 59 } ); 60 53 61 // Schedule cron events. 54 62 add_action( 'shutdown', function() {
Note: See TracChangeset
for help on using the changeset viewer.