Changeset 922 for plugins/staticcache/trunk/staticcache.plugin.php
- Timestamp:
- 09/12/08 19:58:18 (4 months ago)
- Files:
-
- 1 modified
-
plugins/staticcache/trunk/staticcache.plugin.php (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
plugins/staticcache/trunk/staticcache.plugin.php
r672 r922 46 46 if ( isset( $cache[$query_id] ) ) { 47 47 global $profile_start; 48 echo $cache[$query_id]; 48 49 foreach( $cache[$query_id]['headers'] as $header ) { 50 header($header); 51 } 52 echo $cache[$query_id]['body']; 49 53 $time = microtime(true) - $profile_start; 50 54 echo "<!-- Served by StaticCache in $time seconds -->"; … … 53 57 ( Options::get('staticcache__average_time') + $time ) / 2 54 58 ); 59 Options::set('staticcache__hits', Options::get('staticcache__hits') + 1); 55 60 exit; 56 61 } 57 62 } 63 Options::set('staticcache__misses', Options::get('staticcache__misses') + 1); 58 64 ob_start( 'StaticCache_ob_end_flush' ); 59 65 } … … 68 74 public function filter_dash_module_static_cache( $module, $id, $theme ) 69 75 { 70 $theme->static_cache_average = sprintf( '% 0.4f', Options::get('staticcache__average_time') );76 $theme->static_cache_average = sprintf( '%.4f', Options::get('staticcache__average_time') ); 71 77 $theme->static_cache_pages = count( Cache::get_group('staticcache') ); 78 79 $hits = Options::get('staticcache__hits'); 80 $misses = Options::get('staticcache__misses'); 81 $total = $hits + $misses; 82 $theme->static_cache_hits = sprintf('%.0f', $total > 0 ? ($hits/$total)*100 : 0); 83 $theme->static_cache_misses = sprintf('%.0f', $total > 0 ? ($misses/$total)*100 : 0); 84 72 85 $module['content'] = $theme->fetch( 'static_cache_stats' ); 73 86 return $module; … … 133 146 } 134 147 148 /** 149 * @todo add expire time option 150 * @todo add invalidate cache button 151 */ 135 152 public function action_plugin_ui( $plugin_id, $action ) 136 153 { … … 158 175 public static function get_query_id() 159 176 { 160 return crc32( parse_url( $_SERVER['REQUEST_URI'], PHP_URL_QUERY) );177 return crc32( parse_url($_SERVER['REQUEST_URI'], PHP_URL_QUERY) ); 161 178 } 162 179 … … 168 185 } 169 186 if ( ! $url ) { 170 $url = Site::get_url( 'host' ) . rtrim( parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH), '/' );187 $url = Site::get_url( 'host' ) . rtrim( parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), '/' ); 171 188 } 172 189 return crc32( $user_id . $url ); … … 176 193 function StaticCache_ob_end_flush( $buffer ) 177 194 { 195 // prevent caching of 404 responses 196 if ( !URL::get_matched_rule() || URL::get_matched_rule()->name == 'display_404' ) { 197 return false; 198 } 178 199 $request_id = StaticCache::get_request_id(); 179 200 $query_id = StaticCache::get_query_id(); 180 201 181 if ( Cache::has( array("staticcache", $request_id) ) ) { 182 $cache = Cache::get( array("staticcache", $request_id) ); 183 $cache[$query_id] = $buffer; 184 } 185 else { 186 $cache = array( $query_id => $buffer ); 187 } 202 $cache = array( $query_id => array( 203 'headers' => headers_list(), 204 'body' => $buffer 205 )); 188 206 Cache::set( array("staticcache", $request_id), $cache ); 189 207
