LiteSpeed Cache - Version 2.2

Version Description

  • Apr 2 2018 =
  • [NEW FEATURE] Debug Disable All Features setting in Debug tab. (@monarobase)
  • [NEW FEATURE] Cache Force Cacheable URIs setting in Excludes tab.
  • [NEW FEATURE] Purge Purge all LSCache and other caches in one link.
  • [REFACTOR] Purge Refactored Purge class.
  • [BUGFIX] Query strings in DoNotCacheURI setting now works.
  • [BUGFIX] Cache Mobile cache compatibility with WebP vary. (@Shivam #987121)
  • [UPDATE] Purge Moved purge_all to Purge class from core class.
  • [API] Set cacheable/Set force cacheable. (@Jacob)
Download this release

Release Info

Developer LiteSpeedTech
Plugin Icon 128x128 LiteSpeed Cache
Version 2.2
Comparing to
See all releases

Code changes from version 2.1.2 to 2.2

admin/litespeed-cache-admin-settings.class.php CHANGED
@@ -55,7 +55,7 @@ class LiteSpeed_Cache_Admin_Settings
55
*/
56
public function validate_plugin_settings( $input )
57
{
58
- LiteSpeed_Cache_Log::debug( 'Settings: validate_plugin_settings called' ) ;
59
$this->_options = LiteSpeed_Cache_Config::get_instance()->get_options() ;
60
61
if ( LiteSpeed_Cache_Admin_Display::get_instance()->get_disable_all() ) {
@@ -98,7 +98,7 @@ class LiteSpeed_Cache_Admin_Settings
98
$new_esi_enabled = $this->_options[ LiteSpeed_Cache_Config::OPID_ESI_ENABLE ] ;
99
100
if ( $orig_esi_enabled !== $new_esi_enabled ) {
101
- LiteSpeed_Cache_Purge::purge_all() ;
102
}
103
}
104
@@ -194,7 +194,7 @@ class LiteSpeed_Cache_Admin_Settings
194
}
195
}
196
else {
197
- LiteSpeed_Cache_Purge::purge_all() ;
198
}
199
}
200
@@ -202,7 +202,7 @@ class LiteSpeed_Cache_Admin_Settings
202
$orig_primary = $options[ $id ] ;
203
$options[ $id ] = self::parse_onoff( $this->_input, $id ) ;
204
if ( $orig_primary != $options[ $id ] ) {
205
- LiteSpeed_Cache_Purge::purge_all() ;
206
}
207
208
$id = LiteSpeed_Cache_Config::OPID_PURGE_ON_UPGRADE ;
@@ -295,20 +295,22 @@ class LiteSpeed_Cache_Admin_Settings
295
/**
296
* Check if object cache file existing or not
297
*/
298
- $id = LiteSpeed_Cache_Config::OPID_CACHE_OBJECT ;
299
- if ( $new_options[ $id ] ) {
300
- $all_options = array_merge( $new_options, $item_options ) ;
301
- LiteSpeed_Cache_Log::debug( 'Settings: Update .object_cache.ini and flush object cache' ) ;
302
- LiteSpeed_Cache_Object::get_instance()->update_file( true, $all_options ) ;
303
- /**
304
- * Clear object cache
305
- */
306
- LiteSpeed_Cache_Object::get_instance()->reconnect( $all_options ) ;
307
- }
308
- else {
309
- if ( defined( 'LSCWP_OBJECT_CACHE' ) ) {
310
- LiteSpeed_Cache_Log::debug( 'Settings: Remove .object_cache.ini' ) ;
311
- LiteSpeed_Cache_Object::get_instance()->update_file( false ) ;
312
}
313
}
314
@@ -336,7 +338,7 @@ class LiteSpeed_Cache_Admin_Settings
336
337
// Purge when disabled
338
if ( ! $enabled ) {
339
- LiteSpeed_Cache_Purge::purge_all() ;
340
! defined( 'LITESPEED_NEW_OFF' ) && define( 'LITESPEED_NEW_OFF', true ) ; // Latest status is off
341
}
342
else {
@@ -469,6 +471,11 @@ class LiteSpeed_Cache_Admin_Settings
469
*/
470
private function _validate_exclude()
471
{
472
$id = LiteSpeed_Cache_Config::OPID_EXCLUDES_URI ;
473
if ( isset( $this->_input[ $id ] ) ) {
474
$this->_options[ $id ] = LiteSpeed_Cache_Utility::sanitize_lines( $this->_input[ $id ], 'relative' ) ;
@@ -660,7 +667,7 @@ class LiteSpeed_Cache_Admin_Settings
660
}
661
else {
662
$this->_options[ LiteSpeed_Cache_Config::OPID_CDN_CLOUDFLARE_ZONE ] = '' ;
663
- LiteSpeed_Cache_Log::debug( 'Settings: Get zone failed, clean zone' ) ;
664
}
665
}
666
}
@@ -800,16 +807,16 @@ class LiteSpeed_Cache_Admin_Settings
800
// if ( ! empty( $_FILES[ 'litespeed-file-favicon_' . $v ][ 'name' ] ) ) {
801
// $file = wp_handle_upload( $_FILES[ 'litespeed-file-favicon_' . $v ], array( 'action' => 'update' ) ) ;
802
// if ( ! empty( $file[ 'url' ] ) ) {
803
- // LiteSpeed_Cache_Log::debug( 'Settings: Updated favicon [' . $v . '] ' . $file[ 'url' ] ) ;
804
805
// $new_favicons[ $v ] = $file[ 'url' ] ;
806
807
// }
808
// elseif ( isset( $file[ 'error' ] ) ) {
809
- // LiteSpeed_Cache_Log::debug( 'Settings: Failed to update favicon: [' . $v . '] ' . $file[ 'error' ] ) ;
810
// }
811
// else {
812
- // LiteSpeed_Cache_Log::debug( 'Settings: Failed to update favicon: Unkown err [' . $v . ']' ) ;
813
// }
814
// }
815
// }
@@ -863,6 +870,7 @@ class LiteSpeed_Cache_Admin_Settings
863
}
864
865
$ids = array(
866
LiteSpeed_Cache_Config::OPID_DEBUG_LEVEL,
867
LiteSpeed_Cache_Config::OPID_HEARTBEAT,
868
LiteSpeed_Cache_Config::OPID_DEBUG_COOKIE,
@@ -873,6 +881,13 @@ class LiteSpeed_Cache_Admin_Settings
873
$this->_options[ $id ] = self::parse_onoff( $this->_input, $id ) ;
874
}
875
876
// Filters ignored
877
$ids = array(
878
LiteSpeed_Cache_Config::ITEM_LOG_IGNORE_FILTERS,
@@ -1166,13 +1181,13 @@ class LiteSpeed_Cache_Admin_Settings
1166
$instance[ LiteSpeed_Cache_Config::OPTION_NAME ][ LiteSpeed_Cache_ESI::WIDGET_OPID_TTL ] = $ttl ;
1167
1168
if ( ! $current || $esi != $current[ LiteSpeed_Cache_ESI::WIDGET_OPID_ESIENABLE ] ) {
1169
- LiteSpeed_Cache_Purge::purge_all() ;
1170
}
1171
elseif ( $ttl != 0 && $ttl != $current[ LiteSpeed_Cache_ESI::WIDGET_OPID_TTL ] ) {
1172
LiteSpeed_Cache_Purge::add( LiteSpeed_Cache_Tag::TYPE_WIDGET . $widget->id ) ;
1173
}
1174
1175
- LiteSpeed_Cache_Purge::purge_all() ;
1176
return $instance ;
1177
}
1178
55
*/
56
public function validate_plugin_settings( $input )
57
{
58
+ LiteSpeed_Cache_Log::debug( '[Settings] validate_plugin_settings called' ) ;
59
$this->_options = LiteSpeed_Cache_Config::get_instance()->get_options() ;
60
61
if ( LiteSpeed_Cache_Admin_Display::get_instance()->get_disable_all() ) {
98
$new_esi_enabled = $this->_options[ LiteSpeed_Cache_Config::OPID_ESI_ENABLE ] ;
99
100
if ( $orig_esi_enabled !== $new_esi_enabled ) {
101
+ LiteSpeed_Cache_Purge::purge_all( 'ESI changed' ) ;
102
}
103
}
104
194
}
195
}
196
else {
197
+ LiteSpeed_Cache_Purge::purge_all( 'Network enable changed' ) ;
198
}
199
}
200
202
$orig_primary = $options[ $id ] ;
203
$options[ $id ] = self::parse_onoff( $this->_input, $id ) ;
204
if ( $orig_primary != $options[ $id ] ) {
205
+ LiteSpeed_Cache_Purge::purge_all( 'Network use_primary changed' ) ;
206
}
207
208
$id = LiteSpeed_Cache_Config::OPID_PURGE_ON_UPGRADE ;
295
/**
296
* Check if object cache file existing or not
297
*/
298
+ if ( ! defined( 'LITESPEED_DISABLE_OBJECT' ) ) {
299
+ $id = LiteSpeed_Cache_Config::OPID_CACHE_OBJECT ;
300
+ if ( $new_options[ $id ] ) {
301
+ $all_options = array_merge( $new_options, $item_options ) ;
302
+ LiteSpeed_Cache_Log::debug( '[Settings] Update .object_cache.ini and flush object cache' ) ;
303
+ LiteSpeed_Cache_Object::get_instance()->update_file( true, $all_options ) ;
304
+ /**
305
+ * Clear object cache
306
+ */
307
+ LiteSpeed_Cache_Object::get_instance()->reconnect( $all_options ) ;
308
+ }
309
+ else {
310
+ if ( defined( 'LSCWP_OBJECT_CACHE' ) ) {
311
+ LiteSpeed_Cache_Log::debug( '[Settings] Remove .object_cache.ini' ) ;
312
+ LiteSpeed_Cache_Object::get_instance()->update_file( false ) ;
313
+ }
314
}
315
}
316
338
339
// Purge when disabled
340
if ( ! $enabled ) {
341
+ LiteSpeed_Cache_Purge::purge_all( 'Not enabled' ) ;
342
! defined( 'LITESPEED_NEW_OFF' ) && define( 'LITESPEED_NEW_OFF', true ) ; // Latest status is off
343
}
344
else {
471
*/
472
private function _validate_exclude()
473
{
474
+ $id = LiteSpeed_Cache_Config::OPID_FORCE_CACHE_URI ;
475
+ if ( isset( $this->_input[ $id ] ) ) {
476
+ $this->_options[ $id ] = LiteSpeed_Cache_Utility::sanitize_lines( $this->_input[ $id ], 'relative' ) ;
477
+ }
478
+
479
$id = LiteSpeed_Cache_Config::OPID_EXCLUDES_URI ;
480
if ( isset( $this->_input[ $id ] ) ) {
481
$this->_options[ $id ] = LiteSpeed_Cache_Utility::sanitize_lines( $this->_input[ $id ], 'relative' ) ;
667
}
668
else {
669
$this->_options[ LiteSpeed_Cache_Config::OPID_CDN_CLOUDFLARE_ZONE ] = '' ;
670
+ LiteSpeed_Cache_Log::debug( '[Settings] Get zone failed, clean zone' ) ;
671
}
672
}
673
}
807
// if ( ! empty( $_FILES[ 'litespeed-file-favicon_' . $v ][ 'name' ] ) ) {
808
// $file = wp_handle_upload( $_FILES[ 'litespeed-file-favicon_' . $v ], array( 'action' => 'update' ) ) ;
809
// if ( ! empty( $file[ 'url' ] ) ) {
810
+ // LiteSpeed_Cache_Log::debug( '[Settings] Updated favicon [' . $v . '] ' . $file[ 'url' ] ) ;
811
812
// $new_favicons[ $v ] = $file[ 'url' ] ;
813
814
// }
815
// elseif ( isset( $file[ 'error' ] ) ) {
816
+ // LiteSpeed_Cache_Log::debug( '[Settings] Failed to update favicon: [' . $v . '] ' . $file[ 'error' ] ) ;
817
// }
818
// else {
819
+ // LiteSpeed_Cache_Log::debug( '[Settings] Failed to update favicon: Unkown err [' . $v . ']' ) ;
820
// }
821
// }
822
// }
870
}
871
872
$ids = array(
873
+ LiteSpeed_Cache_Config::OPID_DEBUG_DISABLE_ALL,
874
LiteSpeed_Cache_Config::OPID_DEBUG_LEVEL,
875
LiteSpeed_Cache_Config::OPID_HEARTBEAT,
876
LiteSpeed_Cache_Config::OPID_DEBUG_COOKIE,
881
$this->_options[ $id ] = self::parse_onoff( $this->_input, $id ) ;
882
}
883
884
+ // Remove Object Cache
885
+ if ( $this->_options[ LiteSpeed_Cache_Config::OPID_DEBUG_DISABLE_ALL ] ) {
886
+ LiteSpeed_Cache_Log::debug( '[Settings] Remove .object_cache.ini due to debug_disable_all' ) ;
887
+ LiteSpeed_Cache_Object::get_instance()->update_file( false ) ;
888
+ define( 'LITESPEED_DISABLE_OBJECT', true ) ;
889
+ }
890
+
891
// Filters ignored
892
$ids = array(
893
LiteSpeed_Cache_Config::ITEM_LOG_IGNORE_FILTERS,
1181
$instance[ LiteSpeed_Cache_Config::OPTION_NAME ][ LiteSpeed_Cache_ESI::WIDGET_OPID_TTL ] = $ttl ;
1182
1183
if ( ! $current || $esi != $current[ LiteSpeed_Cache_ESI::WIDGET_OPID_ESIENABLE ] ) {
1184
+ LiteSpeed_Cache_Purge::purge_all( 'Wdiget ESI_enable changed' ) ;
1185
}
1186
elseif ( $ttl != 0 && $ttl != $current[ LiteSpeed_Cache_ESI::WIDGET_OPID_TTL ] ) {
1187
LiteSpeed_Cache_Purge::add( LiteSpeed_Cache_Tag::TYPE_WIDGET . $widget->id ) ;
1188
}
1189
1190
+ LiteSpeed_Cache_Purge::purge_all( 'Wdiget saved' ) ;
1191
return $instance ;
1192
}
1193
admin/tpl/edit_htaccess.php CHANGED
@@ -7,7 +7,6 @@ $htaccess_path = LiteSpeed_Cache_Admin_Rules::get_frontend_htaccess() ;
7
8
// Check if there is `ExpiresDefault` in .htaccess
9
if ( defined( 'LITESPEED_ON' ) ) {
10
- $htaccess_con = Litespeed_File::read( LiteSpeed_Cache_Admin_Rules::get_frontend_htaccess() ) ;
11
if ( $content && stripos( $content, "\nExpiresDefault" ) !== false ) {
12
$is_dismissed = get_option( self::DISMISS_MSG ) ;
13
if ( $is_dismissed !== self::RULECONFLICT_DISMISSED ) {
7
8
// Check if there is `ExpiresDefault` in .htaccess
9
if ( defined( 'LITESPEED_ON' ) ) {
10
if ( $content && stripos( $content, "\nExpiresDefault" ) !== false ) {
11
$is_dismissed = get_option( self::DISMISS_MSG ) ;
12
if ( $is_dismissed !== self::RULECONFLICT_DISMISSED ) {
admin/tpl/manage/manage_purge.php CHANGED
@@ -6,71 +6,76 @@ $_panels = array(
6
array(
7
'title' => __( 'Purge Front Page', 'litespeed-cache' ),
8
'desc' => __( 'This will Purge Front Page only', 'litespeed-cache' ),
9
- 'tag' => LiteSpeed_Cache::ACTION_PURGE_FRONT,
10
'icon' => 'purge-front',
11
),
12
array(
13
'title' => __( 'Purge Pages', 'litespeed-cache' ),
14
'desc' => __( 'This will Purge Pages only', 'litespeed-cache' ),
15
- 'tag' => LiteSpeed_Cache::ACTION_PURGE_PAGES,
16
'icon' => 'purge-pages',
17
),
18
array(
19
- 'title' => __( 'Purge CSS/JS Cache', 'litespeed-cache' ),
20
- 'desc' => __( 'This will purge all minified/combined CSS/JS entries only', 'litespeed-cache' ),
21
- 'tag' => LiteSpeed_Cache::ACTION_PURGE_CSSJS,
22
- 'icon' => 'purge-cssjs',
23
- ),
24
- array(
25
- 'title' => __( 'Purge 403 Error', 'litespeed-cache' ),
26
- 'desc' => __( 'Purge error pages, including 403 pages', 'litespeed-cache' ),
27
- 'tag' => LiteSpeed_Cache::ACTION_PURGE_ERRORS,
28
'icon' => 'purge-403',
29
- 'append_url' => '403',
30
),
31
array(
32
- 'title' => __( 'Purge 404 Error', 'litespeed-cache' ),
33
- 'desc' => __( 'Purge error pages, including 404 pages', 'litespeed-cache' ),
34
- 'tag' => LiteSpeed_Cache::ACTION_PURGE_ERRORS,
35
'icon' => 'purge-404',
36
- 'append_url' => '404',
37
),
38
array(
39
'title' => __( 'Purge 500 Error', 'litespeed-cache' ),
40
'desc' => __( 'Purge error pages, including 500 pages', 'litespeed-cache' ),
41
- 'tag' => LiteSpeed_Cache::ACTION_PURGE_ERRORS,
42
'icon' => 'purge-500',
43
- 'append_url' => '500',
44
),
45
array(
46
- 'title' => __( 'Purge All', 'litespeed-cache' ),
47
- 'desc' => __( 'Purge the cache entries created by this plugin', 'litespeed-cache' ),
48
- 'tag' => LiteSpeed_Cache::ACTION_PURGE_ALL,
49
'icon' => 'purge-all',
50
- 'title_cls' => 'litespeed-warning',
51
),
52
) ;
53
54
if ( defined( 'LSCWP_OBJECT_CACHE' ) ) {
55
$_panels[] = array(
56
- 'title' => __( 'Object Cache Purge All', 'litespeed-cache' ),
57
'desc' => __( 'Purge all the object caches', 'litespeed-cache' ),
58
- 'tag' => LiteSpeed_Cache::ACTION_PURGE,
59
'icon' => 'purge-object',
60
- 'append_url' => LiteSpeed_Cache_Purge::TYPE_OBJECT_PURGE_ALL,
61
) ;
62
}
63
64
if ( LiteSpeed_Cache_Router::opcache_enabled() ) {
65
$_panels[] = array(
66
- 'title' => __( 'Opcode Cache Purge All', 'litespeed-cache' ),
67
'desc' => __( 'Reset the entire opcode cache', 'litespeed-cache' ),
68
- 'tag' => LiteSpeed_Cache::ACTION_PURGE,
69
'icon' => 'purge-opcache',
70
- 'append_url' => LiteSpeed_Cache_Purge::TYPE_OPCACHE_PURGE_ALL,
71
) ;
72
}
73
74
if ( ! is_multisite() || is_network_admin() ) {
75
$_panels[] = array(
76
'title' => __( 'Empty Entire Cache', 'litespeed-cache' ),
@@ -79,7 +84,6 @@ if ( ! is_multisite() || is_network_admin() ) {
79
'tag' => LiteSpeed_Cache::ACTION_PURGE_EMPTYCACHE,
80
'icon' => 'empty-cache',
81
'title_cls' => 'litespeed-danger',
82
- 'newline' => true,
83
'cfm' => esc_html( __( 'This will clear EVERYTHING inside the cache.', 'litespeed-cache' ) ) . ' ' .
84
esc_html( __( 'This may cause heavy load on the server.', 'litespeed-cache' ) ) . ' ' .
85
esc_html( __( 'If only the WordPress site should be purged, use purge all.', 'litespeed-cache' ) )
@@ -95,13 +99,15 @@ if ( ! is_multisite() || is_network_admin() ) {
95
<div class="litespeed-panel-wrapper">
96
97
<?php foreach ( $_panels as $v ): ?>
98
99
<?php if ( ! empty( $v[ 'newline' ] ) ) : ?>
100
<div class='litespeed-col-br'></div>
101
<?php endif; ?>
102
103
<a class="litespeed-panel"
104
- href="<?php echo LiteSpeed_Cache_Utility::build_url( $v[ 'tag' ], ! empty( $v[ 'append_url' ] ) ? $v[ 'append_url' ] : false ) ; ?>"
105
<?php if ( ! empty( $v[ 'cfm' ] ) ) echo 'data-litespeed-cfm="' . $v[ 'cfm' ] . '"' ; ?>
106
>
107
<section class="litespeed-panel-wrapper-icon">
6
array(
7
'title' => __( 'Purge Front Page', 'litespeed-cache' ),
8
'desc' => __( 'This will Purge Front Page only', 'litespeed-cache' ),
9
'icon' => 'purge-front',
10
+ 'append_url' => LiteSpeed_Cache_Purge::TYPE_PURGE_FRONTPAGE,
11
),
12
array(
13
'title' => __( 'Purge Pages', 'litespeed-cache' ),
14
'desc' => __( 'This will Purge Pages only', 'litespeed-cache' ),
15
'icon' => 'purge-pages',
16
+ 'append_url' => LiteSpeed_Cache_Purge::TYPE_PURGE_PAGES,
17
),
18
array(
19
+ 'title' => sprintf( __( 'Purge %s Error', 'litespeed-cache' ), '403' ),
20
+ 'desc' => sprintf( __( 'Purge error pages, including %s pages', 'litespeed-cache' ), '403' ),
21
'icon' => 'purge-403',
22
+ 'append_url' => LiteSpeed_Cache_Purge::TYPE_PURGE_ERROR . '403',
23
),
24
array(
25
+ 'title' => sprintf( __( 'Purge %s Error', 'litespeed-cache' ), '404' ),
26
+ 'desc' => sprintf( __( 'Purge error pages, including %s pages', 'litespeed-cache' ), '404' ),
27
'icon' => 'purge-404',
28
+ 'append_url' => LiteSpeed_Cache_Purge::TYPE_PURGE_ERROR . '404',
29
),
30
array(
31
+ 'title' => sprintf( __( 'Purge %s Error', 'litespeed-cache' ), '403' ),
32
+ 'desc' => sprintf( __( 'Purge error pages, including %s pages', 'litespeed-cache' ), '403' ),
33
'title' => __( 'Purge 500 Error', 'litespeed-cache' ),
34
'desc' => __( 'Purge error pages, including 500 pages', 'litespeed-cache' ),
35
'icon' => 'purge-500',
36
+ 'append_url' => LiteSpeed_Cache_Purge::TYPE_PURGE_ERROR . '500',
37
),
38
array(
39
+ 'title' => __( 'Purge All', 'litespeed-cache' ) . ' - LSCache',
40
+ 'desc' => __( 'Purge the litespeed cache entries created by this plugin', 'litespeed-cache' ),
41
'icon' => 'purge-all',
42
+ 'append_url' => LiteSpeed_Cache_Purge::TYPE_PURGE_ALL_LSCACHE,
43
+ ),
44
+ array(
45
+ 'title' => __( 'Purge All', 'litespeed-cache' ) . ' - ' . __( 'CSS/JS Cache', 'litespeed-cache' ),
46
+ 'desc' => __( 'This will purge all minified/combined CSS/JS entries only', 'litespeed-cache' ),
47
+ 'icon' => 'purge-cssjs',
48
+ 'append_url' => LiteSpeed_Cache_Purge::TYPE_PURGE_ALL_CSSJS,
49
),
50
) ;
51
52
if ( defined( 'LSCWP_OBJECT_CACHE' ) ) {
53
$_panels[] = array(
54
+ 'title' => __( 'Purge All', 'litespeed-cache' ) . ' - ' . __( 'Object Cache', 'litespeed-cache' ),
55
'desc' => __( 'Purge all the object caches', 'litespeed-cache' ),
56
'icon' => 'purge-object',
57
+ 'append_url' => LiteSpeed_Cache_Purge::TYPE_PURGE_ALL_OBJECT,
58
) ;
59
}
60
61
if ( LiteSpeed_Cache_Router::opcache_enabled() ) {
62
$_panels[] = array(
63
+ 'title' => __( 'Purge All', 'litespeed-cache' ) . ' - ' . __( 'Opcode Cache', 'litespeed-cache' ),
64
'desc' => __( 'Reset the entire opcode cache', 'litespeed-cache' ),
65
'icon' => 'purge-opcache',
66
+ 'append_url' => LiteSpeed_Cache_Purge::TYPE_PURGE_ALL_OPCACHE,
67
) ;
68
}
69
70
+ $_panels[] = array(
71
+ 'title' => __( 'Purge All', 'litespeed-cache' ),
72
+ 'desc' => __( 'Purge the cache entries created by this plugin', 'litespeed-cache' ),
73
+ 'icon' => 'purge-all',
74
+ 'title_cls' => 'litespeed-warning',
75
+ 'newline' => true,
76
+ 'append_url' => LiteSpeed_Cache_Purge::TYPE_PURGE_ALL,
77
+ ) ;
78
+
79
if ( ! is_multisite() || is_network_admin() ) {
80
$_panels[] = array(
81
'title' => __( 'Empty Entire Cache', 'litespeed-cache' ),
84
'tag' => LiteSpeed_Cache::ACTION_PURGE_EMPTYCACHE,
85
'icon' => 'empty-cache',
86
'title_cls' => 'litespeed-danger',
87
'cfm' => esc_html( __( 'This will clear EVERYTHING inside the cache.', 'litespeed-cache' ) ) . ' ' .
88
esc_html( __( 'This may cause heavy load on the server.', 'litespeed-cache' ) ) . ' ' .
89
esc_html( __( 'If only the WordPress site should be purged, use purge all.', 'litespeed-cache' ) )
99
<div class="litespeed-panel-wrapper">
100
101
<?php foreach ( $_panels as $v ): ?>
102
+ <?php $tag = ! empty( $v[ 'tag' ] ) ? $v[ 'tag' ] : LiteSpeed_Cache::ACTION_PURGE ; ?>
103
+ <?php $append_url = ! empty( $v[ 'append_url' ] ) ? $v[ 'append_url' ] : false ; ?>
104
105
<?php if ( ! empty( $v[ 'newline' ] ) ) : ?>
106
<div class='litespeed-col-br'></div>
107
<?php endif; ?>
108
109
<a class="litespeed-panel"
110
+ href="<?php echo LiteSpeed_Cache_Utility::build_url( $tag, $append_url ) ; ?>"
111
<?php if ( ! empty( $v[ 'cfm' ] ) ) echo 'data-litespeed-cfm="' . $v[ 'cfm' ] . '"' ; ?>
112
>
113
<section class="litespeed-panel-wrapper-icon">
admin/tpl/setting/settings_debug.php CHANGED
@@ -9,6 +9,16 @@ if ( ! defined( 'WPINC' ) ) die ;
9
</h3>
10
11
<table><tbody>
12
<tr>
13
<th><?php echo __( 'Debug Log', 'litespeed-cache' ) ; ?></th>
14
<td>
@@ -16,13 +26,13 @@ if ( ! defined( 'WPINC' ) ) die ;
16
<?php echo $this->build_radio(
17
LiteSpeed_Cache_Config::OPID_DEBUG,
18
LiteSpeed_Cache_Config::VAL_OFF,
19
- __( 'Off', 'litespeed-cache' )
20
) ; ?>
21
22
<?php echo $this->build_radio(
23
LiteSpeed_Cache_Config::OPID_DEBUG,
24
LiteSpeed_Cache_Config::VAL_ON,
25
- __( 'On', 'litespeed-cache' )
26
) ; ?>
27
28
<?php echo $this->build_radio(
9
</h3>
10
11
<table><tbody>
12
+ <tr>
13
+ <th><?php echo __( 'Disable All Features', 'litespeed-cache' ) ; ?></th>
14
+ <td>
15
+ <?php $this->build_switch( LiteSpeed_Cache_Config::OPID_DEBUG_DISABLE_ALL ) ; ?>
16
+ <div class="litespeed-desc">
17
+ <?php echo __( 'This will disable LSCache and all optimization features for debug purpose.', 'litespeed-cache' ) ; ?>
18
+ </div>
19
+ </td>
20
+ </tr>
21
+
22
<tr>
23
<th><?php echo __( 'Debug Log', 'litespeed-cache' ) ; ?></th>
24
<td>
26
<?php echo $this->build_radio(
27
LiteSpeed_Cache_Config::OPID_DEBUG,
28
LiteSpeed_Cache_Config::VAL_OFF,
29
+ __( 'OFF', 'litespeed-cache' )
30
) ; ?>
31
32
<?php echo $this->build_radio(
33
LiteSpeed_Cache_Config::OPID_DEBUG,
34
LiteSpeed_Cache_Config::VAL_ON,
35
+ __( 'ON', 'litespeed-cache' )
36
) ; ?>
37
38
<?php echo $this->build_radio(
admin/tpl/setting/settings_excludes.php CHANGED
@@ -3,13 +3,31 @@ if ( ! defined( 'WPINC' ) ) die ;
3
?>
4
5
<h3 class="litespeed-title-short">
6
- <?php echo __('Do Not Cache Settings', 'litespeed-cache'); ?>
7
<a href="https://www.litespeedtech.com/support/wiki/doku.php/litespeed_wiki:cache:lscwp:configuration:excludes" target="_blank" class="litespeed-learn-more"><?php echo __('Learn More', 'litespeed-cache') ; ?></a>
8
</h3>
9
10
<?php $this->cache_disabled_warning() ; ?>
11
12
<table><tbody>
13
<tr>
14
<th><?php echo __( 'Do Not Cache URIs', 'litespeed-cache' ) ; ?></th>
15
<td>
3
?>
4
5
<h3 class="litespeed-title-short">
6
+ <?php echo __('Exclude Settings', 'litespeed-cache'); ?>
7
<a href="https://www.litespeedtech.com/support/wiki/doku.php/litespeed_wiki:cache:lscwp:configuration:excludes" target="_blank" class="litespeed-learn-more"><?php echo __('Learn More', 'litespeed-cache') ; ?></a>
8
</h3>
9
10
<?php $this->cache_disabled_warning() ; ?>
11
12
<table><tbody>
13
+ <tr>
14
+ <th><?php echo __( 'Force Cache URIs', 'litespeed-cache' ) ; ?></th>
15
+ <td>
16
+ <?php $this->build_textarea( LiteSpeed_Cache_Config::OPID_FORCE_CACHE_URI ) ; ?>
17
+ <div class="litespeed-desc">
18
+ <?php echo __('Paths containing these strings will be cached regardless of no-cacheable settings.', 'litespeed-cache'); ?>
19
+ <?php echo __('The URLs will be compared to the REQUEST_URI server variable.', 'litespeed-cache'); ?>
20
+ <?php echo sprintf( __( 'For example, for %s, %s can be used here.', 'litespeed-cache' ), '<code>/mypath/mypage?aa=bb</code>', '<code>mypage?aa=</code>' ) ; ?>
21
+ <br />
22
+ <i>
23
+ <?php echo sprintf( __( 'To match the beginning, add %s to the beginning of the item.', 'litespeed-cache' ), '<code>^</code>' ) ; ?>
24
+ <?php echo sprintf( __( 'To do an exact match, add %s to the end of the URL.', 'litespeed-cache' ), '<code>lt;/code>' ) ; ?>
25
+ <?php echo __('One per line.', 'litespeed-cache'); ?>
26
+ </i>
27
+ </div>
28
+ </td>
29
+ </tr>
30
+
31
<tr>
32
<th><?php echo __( 'Do Not Cache URIs', 'litespeed-cache' ) ; ?></th>
33
<td>
cli/litespeed-cache-cli-admin.class.php CHANGED
@@ -33,6 +33,7 @@ class LiteSpeed_Cache_Cli_Admin
33
LiteSpeed_Cache_Config::CRWL_TAGS,
34
LiteSpeed_Cache_Config::CRWL_HTTP2,
35
LiteSpeed_Cache_Config::CRWL_CRON_ACTIVE,
36
LiteSpeed_Cache_Config::OPID_DEBUG_LEVEL,
37
LiteSpeed_Cache_Config::OPID_HEARTBEAT,
38
LiteSpeed_Cache_Config::OPID_DEBUG_COOKIE,
@@ -147,6 +148,7 @@ class LiteSpeed_Cache_Cli_Admin
147
case LiteSpeed_Cache_Config::CRWL_TAGS:
148
case LiteSpeed_Cache_Config::CRWL_HTTP2:
149
case LiteSpeed_Cache_Config::CRWL_CRON_ACTIVE:
150
case LiteSpeed_Cache_Config::OPID_DEBUG_LEVEL:
151
case LiteSpeed_Cache_Config::OPID_HEARTBEAT:
152
case LiteSpeed_Cache_Config::OPID_DEBUG_COOKIE:
33
LiteSpeed_Cache_Config::CRWL_TAGS,
34
LiteSpeed_Cache_Config::CRWL_HTTP2,
35
LiteSpeed_Cache_Config::CRWL_CRON_ACTIVE,
36
+ LiteSpeed_Cache_Config::OPID_DEBUG_DISABLE_ALL,
37
LiteSpeed_Cache_Config::OPID_DEBUG_LEVEL,
38
LiteSpeed_Cache_Config::OPID_HEARTBEAT,
39
LiteSpeed_Cache_Config::OPID_DEBUG_COOKIE,
148
case LiteSpeed_Cache_Config::CRWL_TAGS:
149
case LiteSpeed_Cache_Config::CRWL_HTTP2:
150
case LiteSpeed_Cache_Config::CRWL_CRON_ACTIVE:
151
+ case LiteSpeed_Cache_Config::OPID_DEBUG_DISABLE_ALL:
152
case LiteSpeed_Cache_Config::OPID_DEBUG_LEVEL:
153
case LiteSpeed_Cache_Config::OPID_HEARTBEAT:
154
case LiteSpeed_Cache_Config::OPID_DEBUG_COOKIE:
inc/api.class.php CHANGED
@@ -114,6 +114,28 @@ class LiteSpeed_Cache_API
114
LiteSpeed_Cache_Control::set_nocache( $reason ?: 'api' ) ;
115
}
116
117
/**
118
* Get current not cacheable status
119
*
114
LiteSpeed_Cache_Control::set_nocache( $reason ?: 'api' ) ;
115
}
116
117
+ /**
118
+ * Set cache status to cacheable ( By default cacheable status will be set when called WP hook `wp` )
119
+ *
120
+ * @since 2.2
121
+ * @access public
122
+ */
123
+ public static function set_cacheable( $reason )
124
+ {
125
+ LiteSpeed_Cache_Control::set_cacheable( $reason ) ;
126
+ }
127
+
128
+ /**
129
+ * Set cache status to force cacheable ( Will ignore most kinds of non-cacheable conditions )
130
+ *
131
+ * @since 2.2
132
+ * @access public
133
+ */
134
+ public static function set_force_cacheable( $reason )
135
+ {
136
+ LiteSpeed_Cache_Control::force_cacheable( $reason ) ;
137
+ }
138
+
139
/**
140
* Get current not cacheable status
141
*
inc/config.class.php CHANGED
@@ -95,6 +95,7 @@ class LiteSpeed_Cache_Config
95
// do NOT set default options for these three, it is used for admin.
96
const ID_NOCACHE_COOKIES = 'nocache_cookies' ;
97
const ID_NOCACHE_USERAGENTS = 'nocache_useragents' ;
98
const OPID_DEBUG = 'debug' ;
99
const OPID_ADMIN_IPS = 'admin_ips' ;
100
const OPID_DEBUG_LEVEL = 'debug_level' ;
@@ -126,6 +127,7 @@ class LiteSpeed_Cache_Config
126
const PURGE_DATE = 'D' ;
127
const PURGE_TERM = 'T' ; // include category|tag|tax
128
const PURGE_POST_TYPE = 'PT' ;
129
const OPID_EXCLUDES_URI = 'excludes_uri' ;
130
const OPID_EXCLUDES_QS = 'excludes_qs' ;
131
const OPID_EXCLUDES_CAT = 'excludes_cat' ;
@@ -419,6 +421,10 @@ class LiteSpeed_Cache_Config
419
}
420
421
switch ( $type ) {
422
case 'private' :
423
$id = self::OPID_CACHE_URI_PRIV ;
424
break ;
@@ -446,7 +452,7 @@ class LiteSpeed_Cache_Config
446
$instance->update_options( array( $id => $list ) ) ;
447
448
// Purge this page & redirect
449
- LiteSpeed_Cache_Purge::frontend_purge() ;
450
exit() ;
451
}
452
@@ -606,6 +612,7 @@ class LiteSpeed_Cache_Config
606
self::OPID_LOGIN_COOKIE => '',
607
self::OPID_CHECK_ADVANCEDCACHE => true,
608
self::OPID_USE_HTTP_FOR_HTTPS_VARY => false,
609
self::OPID_DEBUG => self::LOG_LEVEL_NONE,
610
self::OPID_ADMIN_IPS => '127.0.0.1',
611
self::OPID_DEBUG_LEVEL => false,
@@ -622,6 +629,7 @@ class LiteSpeed_Cache_Config
622
self::OPID_404_TTL => 3600,
623
self::OPID_500_TTL => 3600,
624
self::OPID_PURGE_BY_POST => implode('.', $default_purge_options),
625
self::OPID_EXCLUDES_URI => '',
626
self::OPID_EXCLUDES_QS => '',
627
self::OPID_EXCLUDES_CAT => '',
95
// do NOT set default options for these three, it is used for admin.
96
const ID_NOCACHE_COOKIES = 'nocache_cookies' ;
97
const ID_NOCACHE_USERAGENTS = 'nocache_useragents' ;
98
+ const OPID_DEBUG_DISABLE_ALL = 'debug_disable_all' ;
99
const OPID_DEBUG = 'debug' ;
100
const OPID_ADMIN_IPS = 'admin_ips' ;
101
const OPID_DEBUG_LEVEL = 'debug_level' ;
127
const PURGE_DATE = 'D' ;
128
const PURGE_TERM = 'T' ; // include category|tag|tax
129
const PURGE_POST_TYPE = 'PT' ;
130
+ const OPID_FORCE_CACHE_URI = 'forced_cache_uri' ;
131
const OPID_EXCLUDES_URI = 'excludes_uri' ;
132
const OPID_EXCLUDES_QS = 'excludes_qs' ;
133
const OPID_EXCLUDES_CAT = 'excludes_cat' ;
421
}
422
423
switch ( $type ) {
424
+ case 'forced_cache' :
425
+ $id = self::OPID_FORCE_CACHE_URI ;
426
+ break ;
427
+
428
case 'private' :
429
$id = self::OPID_CACHE_URI_PRIV ;
430
break ;
452
$instance->update_options( array( $id => $list ) ) ;
453
454
// Purge this page & redirect
455
+ LiteSpeed_Cache_Purge::purge_front() ;
456
exit() ;
457
}
458
612
self::OPID_LOGIN_COOKIE => '',
613
self::OPID_CHECK_ADVANCEDCACHE => true,
614
self::OPID_USE_HTTP_FOR_HTTPS_VARY => false,
615
+ self::OPID_DEBUG_DISABLE_ALL => false,
616
self::OPID_DEBUG => self::LOG_LEVEL_NONE,
617
self::OPID_ADMIN_IPS => '127.0.0.1',
618
self::OPID_DEBUG_LEVEL => false,
629
self::OPID_404_TTL => 3600,
630
self::OPID_500_TTL => 3600,
631
self::OPID_PURGE_BY_POST => implode('.', $default_purge_options),
632
+ self::OPID_FORCE_CACHE_URI => '',
633
self::OPID_EXCLUDES_URI => '',
634
self::OPID_EXCLUDES_QS => '',
635
self::OPID_EXCLUDES_CAT => '',
inc/control.class.php CHANGED
@@ -16,6 +16,7 @@ class LiteSpeed_Cache_Control
16
const BM_PRIVATE = 2 ;
17
const BM_SHARED = 4 ;
18
const BM_NO_VARY = 8 ;
19
const BM_PUBLIC_FORCED = 64 ;
20
const BM_STALE = 128 ;
21
const BM_NOTCACHEABLE = 256 ;
@@ -78,7 +79,7 @@ class LiteSpeed_Cache_Control
78
// NOTE: If any strange resource doesn't use normal WP logic `wp_loaded` hook, rewrite rule can handle it
79
$cache_res = LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPID_CACHE_RES ) ;
80
if ( $cache_res ) {
81
- $uri = esc_url( $_SERVER["REQUEST_URI"] ) ;
82
$pattern = '!' . LSCWP_CONTENT_FOLDER . LiteSpeed_Cache_Admin_Rules::RW_PATTERN_RES . '!' ;
83
if ( preg_match( $pattern, $uri ) ) {
84
add_action( 'wp_loaded', 'LiteSpeed_Cache_Control::set_cacheable', 5 ) ;
@@ -238,10 +239,34 @@ class LiteSpeed_Cache_Control
238
* @access public
239
* @since 1.1.3
240
*/
241
- public static function set_cacheable()
242
{
243
self::$_control |= self::BM_CACHEABLE ;
244
- LiteSpeed_Cache_Log::debug( '[Ctrl] X Cache_control init on' ) ;
245
}
246
247
/**
@@ -272,6 +297,17 @@ class LiteSpeed_Cache_Control
272
return self::$_control & self::BM_NOTCACHEABLE ;
273
}
274
275
/**
276
* Check current cacheable status
277
*
@@ -281,12 +317,14 @@ class LiteSpeed_Cache_Control
281
*/
282
public static function is_cacheable()
283
{
284
return ! self::isset_notcacheable() && self::$_control & self::BM_CACHEABLE ;
285
}
286
287
-
288
-
289
-
290
/**
291
* Set a custom TTL to use with the request if needed.
292
*
@@ -448,6 +486,16 @@ class LiteSpeed_Cache_Control
448
*/
449
public static function finalize()
450
{
451
// if is not cacheable, terminate check
452
// Even no need to run 3rd party hook
453
if ( ! self::is_cacheable() ) {
@@ -507,7 +555,7 @@ class LiteSpeed_Cache_Control
507
return ;
508
}
509
510
- if ( isset($_SERVER['LSCACHE_VARY_VALUE']) && $_SERVER['LSCACHE_VARY_VALUE'] === 'ismobile' ) {
511
if ( ! wp_is_mobile() && ! self::is_mobile() ) {
512
self::set_nocache( 'is not mobile' ) ;
513
return ;
@@ -562,66 +610,65 @@ class LiteSpeed_Cache_Control
562
// Check private cache URI setting
563
$excludes = LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPID_CACHE_URI_PRIV ) ;
564
if ( ! empty( $excludes ) ) {
565
- $uri = esc_url( $_SERVER[ 'REQUEST_URI' ] ) ;
566
- $result = LiteSpeed_Cache_Utility::str_hit_array( $uri, explode( "\n", $excludes ) ) ;
567
if ( $result ) {
568
self::set_private( 'Admin cfg Private Cached URI: ' . $result ) ;
569
}
570
}
571
572
- // Check if URI is excluded from cache
573
- $excludes = LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPID_EXCLUDES_URI ) ;
574
- if ( ! empty( $excludes ) ) {
575
- $uri = esc_url( $_SERVER[ 'REQUEST_URI' ] ) ;
576
- $result = LiteSpeed_Cache_Utility::str_hit_array( $uri, explode( "\n", $excludes ) ) ;
577
- if ( $result ) {
578
- return $this->_no_cache_for( 'Admin configured URI Do not cache: ' . $result ) ;
579
}
580
- }
581
582
- // Check QS excluded setting
583
- $excludes = LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPID_EXCLUDES_QS ) ;
584
- if ( ! empty( $excludes ) && $qs = $this->_is_qs_excluded( explode( "\n", $excludes ) ) ) {
585
- return $this->_no_cache_for( 'Admin configured QS Do not cache: ' . $qs ) ;
586
- }
587
588
- $excludes = LiteSpeed_Cache::config(LiteSpeed_Cache_Config::OPID_EXCLUDES_CAT) ;
589
- if ( ! empty($excludes) && has_category(explode(',', $excludes)) ) {
590
- return $this->_no_cache_for('Admin configured Category Do not cache.') ;
591
- }
592
593
- $excludes = LiteSpeed_Cache::config(LiteSpeed_Cache_Config::OPID_EXCLUDES_TAG) ;
594
- if ( ! empty($excludes) && has_tag(explode(',', $excludes)) ) {
595
- return $this->_no_cache_for('Admin configured Tag Do not cache.') ;
596
- }
597
598
- $excludes = LiteSpeed_Cache::config(LiteSpeed_Cache_Config::ID_NOCACHE_COOKIES) ;
599
- if ( ! empty($excludes) && ! empty($_COOKIE) ) {
600
- $exclude_list = explode('|', $excludes) ;
601
602
- foreach( $_COOKIE as $key=>$val) {
603
- if ( in_array($key, $exclude_list) ) {
604
- return $this->_no_cache_for('Admin configured Cookie Do not cache.') ;
605
}
606
}
607
- }
608
609
- $excludes = LiteSpeed_Cache::config(LiteSpeed_Cache_Config::ID_NOCACHE_USERAGENTS) ;
610
- if ( ! empty($excludes) && isset($_SERVER['HTTP_USER_AGENT']) ) {
611
- $pattern = '/' . $excludes . '/' ;
612
- $nummatches = preg_match($pattern, $_SERVER['HTTP_USER_AGENT']) ;
613
- if ( $nummatches ) {
614
- return $this->_no_cache_for('Admin configured User Agent Do not cache.') ;
615
}
616
- }
617
618
- // Check if is exclude roles ( Need to set Vary too )
619
- if ( $result = LiteSpeed_Cache_Config::get_instance()->in_exclude_cache_roles() ) {
620
- return $this->_no_cache_for( 'Role Excludes setting ' . $result ) ;
621
}
622
623
-
624
-
625
return true ;
626
}
627
16
const BM_PRIVATE = 2 ;
17
const BM_SHARED = 4 ;
18
const BM_NO_VARY = 8 ;
19
+ const BM_FORCED_CACHEABLE = 32 ;
20
const BM_PUBLIC_FORCED = 64 ;
21
const BM_STALE = 128 ;
22
const BM_NOTCACHEABLE = 256 ;
79
// NOTE: If any strange resource doesn't use normal WP logic `wp_loaded` hook, rewrite rule can handle it
80
$cache_res = LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPID_CACHE_RES ) ;
81
if ( $cache_res ) {
82
+ $uri = esc_url( $_SERVER["REQUEST_URI"] ) ;// todo: check if need esc_url()
83
$pattern = '!' . LSCWP_CONTENT_FOLDER . LiteSpeed_Cache_Admin_Rules::RW_PATTERN_RES . '!' ;
84
if ( preg_match( $pattern, $uri ) ) {
85
add_action( 'wp_loaded', 'LiteSpeed_Cache_Control::set_cacheable', 5 ) ;
239
* @access public
240
* @since 1.1.3
241
*/
242
+ public static function set_cacheable( $reason = false )
243
{
244
self::$_control |= self::BM_CACHEABLE ;
245
+
246
+ if ( ! is_string( $reason ) ) {
247
+ $reason = false ;
248
+ }
249
+
250
+ if ( $reason ) {
251
+ $reason = ' [reason] ' . $reason ;
252
+ }
253
+ LiteSpeed_Cache_Log::debug( '[Ctrl] X Cache_control init on' . $reason ) ;
254
+ }
255
+
256
+ /**
257
+ * This will disable non-cacheable BM
258
+ *
259
+ * @access public
260
+ * @since 2.2
261
+ */
262
+ public static function force_cacheable( $reason = false )
263
+ {
264
+ self::$_control |= self::BM_FORCED_CACHEABLE ;
265
+
266
+ if ( $reason ) {
267
+ $reason = ' [reason] ' . $reason ;
268
+ }
269
+ LiteSpeed_Cache_Log::debug( '[Ctrl] Forced cacheable' . $reason ) ;
270
}
271
272
/**
297
return self::$_control & self::BM_NOTCACHEABLE ;
298
}
299
300
+ /**
301
+ * Check current force cacheable bit set
302
+ *
303
+ * @access public
304
+ * @since 2.2
305
+ */
306
+ public static function is_forced_cacheable()
307
+ {
308
+ return self::$_control & self::BM_FORCED_CACHEABLE ;
309
+ }
310
+
311
/**
312
* Check current cacheable status
313
*
317
*/
318
public static function is_cacheable()
319
{
320
+ // If its forced cacheable
321
+ if ( self::is_forced_cacheable() ) {
322
+ return true ;
323
+ }
324
+
325
return ! self::isset_notcacheable() && self::$_control & self::BM_CACHEABLE ;
326
}
327
328
/**
329
* Set a custom TTL to use with the request if needed.
330
*
486
*/
487
public static function finalize()
488
{
489
+ // Check if URI is forced cache
490
+ $excludes = LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPID_FORCE_CACHE_URI ) ;
491
+ if ( ! empty( $excludes ) ) {
492
+ $result = LiteSpeed_Cache_Utility::str_hit_array( $_SERVER[ 'REQUEST_URI' ], explode( "\n", $excludes ) ) ;
493
+ if ( $result ) {
494
+ self::force_cacheable() ;
495
+ LiteSpeed_Cache_Log::debug( '[Ctrl] Forced cacheable due to setting: ' . $result ) ;
496
+ }
497
+ }
498
+
499
// if is not cacheable, terminate check
500
// Even no need to run 3rd party hook
501
if ( ! self::is_cacheable() ) {
555
return ;
556
}
557
558
+ if ( isset($_SERVER['LSCACHE_VARY_VALUE']) && strpos( $_SERVER['LSCACHE_VARY_VALUE'], 'ismobile' ) !== false ) {
559
if ( ! wp_is_mobile() && ! self::is_mobile() ) {
560
self::set_nocache( 'is not mobile' ) ;
561
return ;
610
// Check private cache URI setting
611
$excludes = LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPID_CACHE_URI_PRIV ) ;
612
if ( ! empty( $excludes ) ) {
613
+ $result = LiteSpeed_Cache_Utility::str_hit_array( $_SERVER[ 'REQUEST_URI' ], explode( "\n", $excludes ) ) ;
614
if ( $result ) {
615
self::set_private( 'Admin cfg Private Cached URI: ' . $result ) ;
616
}
617
}
618
619
+ if ( ! self::is_forced_cacheable() ) {
620
+
621
+ // Check if URI is excluded from cache
622
+ $excludes = LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPID_EXCLUDES_URI ) ;
623
+ if ( ! empty( $excludes ) ) {
624
+ $result = LiteSpeed_Cache_Utility::str_hit_array( $_SERVER[ 'REQUEST_URI' ], explode( "\n", $excludes ) ) ;
625
+ if ( $result ) {
626
+ return $this->_no_cache_for( 'Admin configured URI Do not cache: ' . $result ) ;
627
+ }
628
}
629
630
+ // Check QS excluded setting
631
+ $excludes = LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPID_EXCLUDES_QS ) ;
632
+ if ( ! empty( $excludes ) && $qs = $this->_is_qs_excluded( explode( "\n", $excludes ) ) ) {
633
+ return $this->_no_cache_for( 'Admin configured QS Do not cache: ' . $qs ) ;
634
+ }
635
636
+ $excludes = LiteSpeed_Cache::config(LiteSpeed_Cache_Config::OPID_EXCLUDES_CAT) ;
637
+ if ( ! empty($excludes) && has_category(explode(',', $excludes)) ) {
638
+ return $this->_no_cache_for('Admin configured Category Do not cache.') ;
639
+ }
640
641
+ $excludes = LiteSpeed_Cache::config(LiteSpeed_Cache_Config::OPID_EXCLUDES_TAG) ;
642
+ if ( ! empty($excludes) && has_tag(explode(',', $excludes)) ) {
643
+ return $this->_no_cache_for('Admin configured Tag Do not cache.') ;
644
+ }
645
646
+ $excludes = LiteSpeed_Cache::config(LiteSpeed_Cache_Config::ID_NOCACHE_COOKIES) ;
647
+ if ( ! empty($excludes) && ! empty($_COOKIE) ) {
648
+ $exclude_list = explode('|', $excludes) ;
649
650
+ foreach( $_COOKIE as $key=>$val) {
651
+ if ( in_array($key, $exclude_list) ) {
652
+ return $this->_no_cache_for('Admin configured Cookie Do not cache.') ;
653
+ }
654
}
655
}
656
657
+ $excludes = LiteSpeed_Cache::config(LiteSpeed_Cache_Config::ID_NOCACHE_USERAGENTS) ;
658
+ if ( ! empty($excludes) && isset($_SERVER['HTTP_USER_AGENT']) ) {
659
+ $pattern = '/' . $excludes . '/' ;
660
+ $nummatches = preg_match($pattern, $_SERVER['HTTP_USER_AGENT']) ;
661
+ if ( $nummatches ) {
662
+ return $this->_no_cache_for('Admin configured User Agent Do not cache.') ;
663
+ }
664
}
665
666
+ // Check if is exclude roles ( Need to set Vary too )
667
+ if ( $result = LiteSpeed_Cache_Config::get_instance()->in_exclude_cache_roles() ) {
668
+ return $this->_no_cache_for( 'Role Excludes setting ' . $result ) ;
669
+ }
670
}
671
672
return true ;
673
}
674
inc/gui.class.php CHANGED
@@ -275,7 +275,7 @@ class LiteSpeed_Cache_GUI
275
'parent' => 'litespeed-menu',
276
'id' => 'litespeed-purge-single',
277
'title' => __( 'Purge this page', 'litespeed-cache' ),
278
- 'href' => LiteSpeed_Cache_Utility::build_url( LiteSpeed_Cache::ACTION_FRONT_PURGE, false, false, true ),
279
'meta' => array( 'tabindex' => '0' ),
280
) );
281
@@ -286,6 +286,13 @@ class LiteSpeed_Cache_GUI
286
'meta' => array( 'tabindex' => '0' ),
287
) );
288
289
$wp_admin_bar->add_menu( array(
290
'parent' => 'litespeed-single-action',
291
'id' => 'litespeed-single-noncache',
@@ -331,7 +338,7 @@ class LiteSpeed_Cache_GUI
331
$wp_admin_bar->add_menu( array(
332
'id' => 'litespeed-menu',
333
'title' => '<span class="ab-icon" title="' . __( 'LiteSpeed Cache Purge All', 'litespeed-cache' ) . '""></span>',
334
- 'href' => LiteSpeed_Cache_Utility::build_url( LiteSpeed_Cache::ACTION_PURGE_ALL ),
335
'meta' => array( 'tabindex' => 0, 'class' => 'litespeed-top-toolbar' ),
336
) ) ;
337
}
@@ -372,16 +379,24 @@ class LiteSpeed_Cache_GUI
372
$wp_admin_bar->add_menu( array(
373
'parent' => 'litespeed-menu',
374
'id' => 'litespeed-purge-all',
375
- 'title' => __( 'LSCache Purge All', 'litespeed-cache' ),
376
- 'href' => LiteSpeed_Cache_Utility::build_url( LiteSpeed_Cache::ACTION_PURGE_ALL ),
377
'meta' => array( 'tabindex' => '0' ),
378
) );
379
380
$wp_admin_bar->add_menu( array(
381
'parent' => 'litespeed-menu',
382
'id' => 'litespeed-purge-cssjs',
383
- 'title' => __( 'Purge CSS/JS Cache', 'litespeed-cache' ),
384
- 'href' => LiteSpeed_Cache_Utility::build_url( LiteSpeed_Cache::ACTION_PURGE_CSSJS ),
385
'meta' => array( 'tabindex' => '0' ),
386
) );
387
@@ -389,7 +404,7 @@ class LiteSpeed_Cache_GUI
389
$wp_admin_bar->add_menu( array(
390
'parent' => 'litespeed-menu',
391
'id' => 'litespeed-purge-cloudflare',
392
- 'title' => __( 'Cloudflare Purge All', 'litespeed-cache' ),
393
'href' => LiteSpeed_Cache_Utility::build_url( LiteSpeed_Cache::ACTION_CDN_CLOUDFLARE, LiteSpeed_Cache_CDN_Cloudflare::TYPE_PURGE_ALL ),
394
'meta' => array( 'tabindex' => '0' ),
395
) );
@@ -399,8 +414,8 @@ class LiteSpeed_Cache_GUI
399
$wp_admin_bar->add_menu( array(
400
'parent' => 'litespeed-menu',
401
'id' => 'litespeed-purge-object',
402
- 'title' => __( 'Object Cache Purge All', 'litespeed-cache' ),
403
- 'href' => LiteSpeed_Cache_Utility::build_url( LiteSpeed_Cache::ACTION_PURGE, LiteSpeed_Cache_Purge::TYPE_OBJECT_PURGE_ALL ),
404
'meta' => array( 'tabindex' => '0' ),
405
) );
406
}
@@ -409,8 +424,8 @@ class LiteSpeed_Cache_GUI
409
$wp_admin_bar->add_menu( array(
410
'parent' => 'litespeed-menu',
411
'id' => 'litespeed-purge-opcache',
412
- 'title' => __( 'Opcode Cache Purge All', 'litespeed-cache' ),
413
- 'href' => LiteSpeed_Cache_Utility::build_url( LiteSpeed_Cache::ACTION_PURGE, LiteSpeed_Cache_Purge::TYPE_OPCACHE_PURGE_ALL ),
414
'meta' => array( 'tabindex' => '0' ),
415
) );
416
}
275
'parent' => 'litespeed-menu',
276
'id' => 'litespeed-purge-single',
277
'title' => __( 'Purge this page', 'litespeed-cache' ),
278
+ 'href' => LiteSpeed_Cache_Utility::build_url( LiteSpeed_Cache::ACTION_PURGE, LiteSpeed_Cache_Purge::TYPE_PURGE_FRONT, false, true ),
279
'meta' => array( 'tabindex' => '0' ),
280
) );
281
286
'meta' => array( 'tabindex' => '0' ),
287
) );
288
289
+ $wp_admin_bar->add_menu( array(
290
+ 'parent' => 'litespeed-single-action',
291
+ 'id' => 'litespeed-single-forced_cache',
292
+ 'title' => __( 'Forced cacheable', 'litespeed-cache' ),
293
+ 'href' => LiteSpeed_Cache_Utility::build_url( LiteSpeed_Cache::ACTION_FRONT_EXCLUDE, 'forced_cache', false, true ),
294
+ ) );
295
+
296
$wp_admin_bar->add_menu( array(
297
'parent' => 'litespeed-single-action',
298
'id' => 'litespeed-single-noncache',
338
$wp_admin_bar->add_menu( array(
339
'id' => 'litespeed-menu',
340
'title' => '<span class="ab-icon" title="' . __( 'LiteSpeed Cache Purge All', 'litespeed-cache' ) . '""></span>',
341
+ 'href' => LiteSpeed_Cache_Utility::build_url( LiteSpeed_Cache::ACTION_PURGE, LiteSpeed_Cache_Purge::TYPE_PURGE_ALL ),
342
'meta' => array( 'tabindex' => 0, 'class' => 'litespeed-top-toolbar' ),
343
) ) ;
344
}
379
$wp_admin_bar->add_menu( array(
380
'parent' => 'litespeed-menu',
381
'id' => 'litespeed-purge-all',
382
+ 'title' => __( 'Purge All', 'litespeed-cache' ),
383
+ 'href' => LiteSpeed_Cache_Utility::build_url( LiteSpeed_Cache::ACTION_PURGE, LiteSpeed_Cache_Purge::TYPE_PURGE_ALL ),
384
+ 'meta' => array( 'tabindex' => '0' ),
385
+ ) );
386
+
387
+ $wp_admin_bar->add_menu( array(
388
+ 'parent' => 'litespeed-menu',
389
+ 'id' => 'litespeed-lscache-purge-all',
390
+ 'title' => __( 'Purge All', 'litespeed-cache' ) . ' - ' . __( 'LSCache', 'litespeed-cache' ),
391
+ 'href' => LiteSpeed_Cache_Utility::build_url( LiteSpeed_Cache::ACTION_PURGE, LiteSpeed_Cache_Purge::TYPE_PURGE_ALL_LSCACHE ),
392
'meta' => array( 'tabindex' => '0' ),
393
) );
394
395
$wp_admin_bar->add_menu( array(
396
'parent' => 'litespeed-menu',
397
'id' => 'litespeed-purge-cssjs',
398
+ 'title' => __( 'Purge All', 'litespeed-cache' ) . ' - ' . __( 'CSS/JS Cache', 'litespeed-cache' ),
399
+ 'href' => LiteSpeed_Cache_Utility::build_url( LiteSpeed_Cache::ACTION_PURGE, LiteSpeed_Cache_Purge::TYPE_PURGE_ALL_CSSJS ),
400
'meta' => array( 'tabindex' => '0' ),
401
) );
402
404
$wp_admin_bar->add_menu( array(
405
'parent' => 'litespeed-menu',
406
'id' => 'litespeed-purge-cloudflare',
407
+ 'title' => __( 'Purge All', 'litespeed-cache' ) . ' - ' . __( 'Cloudflare', 'litespeed-cache' ),
408
'href' => LiteSpeed_Cache_Utility::build_url( LiteSpeed_Cache::ACTION_CDN_CLOUDFLARE, LiteSpeed_Cache_CDN_Cloudflare::TYPE_PURGE_ALL ),
409
'meta' => array( 'tabindex' => '0' ),
410
) );
414
$wp_admin_bar->add_menu( array(
415
'parent' => 'litespeed-menu',
416
'id' => 'litespeed-purge-object',
417
+ 'title' => __( 'Purge All', 'litespeed-cache' ) . ' - ' . __( 'Object Cache', 'litespeed-cache' ),
418
+ 'href' => LiteSpeed_Cache_Utility::build_url( LiteSpeed_Cache::ACTION_PURGE, LiteSpeed_Cache_Purge::TYPE_PURGE_ALL_OBJECT ),
419
'meta' => array( 'tabindex' => '0' ),
420
) );
421
}
424
$wp_admin_bar->add_menu( array(
425
'parent' => 'litespeed-menu',
426
'id' => 'litespeed-purge-opcache',
427
+ 'title' => __( 'Purge All', 'litespeed-cache' ) . ' - ' . __( 'Opcode Cache', 'litespeed-cache' ),
428
+ 'href' => LiteSpeed_Cache_Utility::build_url( LiteSpeed_Cache::ACTION_PURGE, LiteSpeed_Cache_Purge::TYPE_PURGE_ALL_OPCACHE ),
429
'meta' => array( 'tabindex' => '0' ),
430
) );
431
}
inc/litespeed-cache.class.php CHANGED
@@ -19,7 +19,7 @@ class LiteSpeed_Cache
19
private static $_instance ;
20
21
const PLUGIN_NAME = 'litespeed-cache' ;
22
- const PLUGIN_VERSION = '2.1.2' ;
23
24
const PAGE_EDIT_HTACCESS = 'lscache-edit-htaccess' ;
25
@@ -29,12 +29,7 @@ class LiteSpeed_Cache
29
const ACTION_SAVE_HTACCESS = 'save-htaccess' ;
30
const ACTION_SAVE_SETTINGS = 'save-settings' ;
31
const ACTION_SAVE_SETTINGS_NETWORK = 'save-settings-network' ;
32
- const ACTION_PURGE_ERRORS = 'PURGE_ERRORS' ;
33
- const ACTION_PURGE_PAGES = 'PURGE_PAGES' ;
34
- const ACTION_PURGE_CSSJS = 'PURGE_CSSJS' ;
35
const ACTION_PURGE_BY = 'PURGE_BY' ;
36
- const ACTION_PURGE_FRONT = 'PURGE_FRONT' ;
37
- const ACTION_PURGE_ALL = 'PURGE_ALL' ;
38
const ACTION_PURGE_EMPTYCACHE = 'PURGE_EMPTYCACHE' ;
39
const ACTION_QS_PURGE = 'PURGE' ;
40
const ACTION_QS_PURGE_SINGLE = 'PURGESINGLE' ;
@@ -50,7 +45,6 @@ class LiteSpeed_Cache
50
const ACTION_CDN_CLOUDFLARE = 'cdn_cloudflare' ;
51
const ACTION_CDN_QUICCLOUD = 'cdn_quiccloud' ;
52
53
- const ACTION_FRONT_PURGE = 'front-purge' ;
54
const ACTION_FRONT_EXCLUDE = 'front-exclude' ;
55
56
const ACTION_DB_OPTIMIZE = 'db_optimize' ;
@@ -99,6 +93,10 @@ class LiteSpeed_Cache
99
include_once LSCWP_DIR . 'thirdparty/lscwp-registry-3rd.php' ;
100
}
101
102
/**
103
* This needs to be before activation because admin-rules.class.php need const `LSCWP_CONTENT_FOLDER`
104
* @since 1.9.1 Moved up
@@ -120,7 +118,7 @@ class LiteSpeed_Cache
120
// Check if there is a purge request in queue
121
if ( $purge_queue = get_option( LiteSpeed_Cache_Purge::PURGE_QUEUE ) ) {
122
@header( $purge_queue ) ;
123
- LiteSpeed_Cache_Log::debug( '[Boot] Purge Queue found&sent: ' . $purge_queue ) ;
124
delete_option( LiteSpeed_Cache_Purge::PURGE_QUEUE ) ;
125
}
126
@@ -171,6 +169,11 @@ class LiteSpeed_Cache
171
// return ;
172
// }
173
174
ob_start( array( $this, 'send_headers_force' ) ) ;
175
add_action( 'shutdown', array( $this, 'send_headers' ), 0 ) ;
176
add_action( 'wp_footer', 'LiteSpeed_Cache::footer_hook' ) ;
@@ -264,30 +267,8 @@ class LiteSpeed_Cache
264
$msg = __( 'Crawler blacklist is saved.', 'litespeed-cache' ) ;
265
break ;
266
267
- case LiteSpeed_Cache::ACTION_PURGE_FRONT:
268
- LiteSpeed_Cache_Purge::purge_front() ;
269
- $msg = __( 'Notified LiteSpeed Web Server to purge the front page.', 'litespeed-cache' ) ;
270
- break ;
271
-
272
- case LiteSpeed_Cache::ACTION_PURGE_PAGES:
273
- LiteSpeed_Cache_Purge::purge_pages() ;
274
- $msg = __( 'Notified LiteSpeed Web Server to purge pages.', 'litespeed-cache' ) ;
275
- break ;
276
-
277
- case LiteSpeed_Cache::ACTION_PURGE_CSSJS:
278
- LiteSpeed_Cache_Purge::purge_cssjs() ;
279
- $msg = __( 'Notified LiteSpeed Web Server to purge CSS/JS entries.', 'litespeed-cache' ) ;
280
- break ;
281
-
282
- case LiteSpeed_Cache::ACTION_PURGE_ERRORS:
283
- LiteSpeed_Cache_Purge::purge_errors() ;
284
- $msg = __( 'Notified LiteSpeed Web Server to purge error pages.', 'litespeed-cache' ) ;
285
- break ;
286
-
287
- case LiteSpeed_Cache::ACTION_PURGE_ALL:
288
case LiteSpeed_Cache::ACTION_QS_PURGE_ALL:
289
LiteSpeed_Cache_Purge::purge_all() ;
290
- $msg = __( 'Notified LiteSpeed Web Server to purge all caches.', 'litespeed-cache' ) ;
291
break;
292
293
case LiteSpeed_Cache::ACTION_PURGE_EMPTYCACHE:
@@ -297,11 +278,6 @@ class LiteSpeed_Cache
297
$msg = __( 'Notified LiteSpeed Web Server to purge everything.', 'litespeed-cache' ) ;
298
break;
299
300
- case LiteSpeed_Cache::ACTION_FRONT_PURGE:
301
- // redirect inside
302
- LiteSpeed_Cache_Purge::frontend_purge() ;
303
- break ;
304
-
305
case LiteSpeed_Cache::ACTION_FRONT_EXCLUDE:
306
// redirect inside
307
LiteSpeed_Cache_Config::frontend_save() ;
@@ -440,7 +416,7 @@ class LiteSpeed_Cache
440
*/
441
public static function footer_hook()
442
{
443
- LiteSpeed_Cache_Log::debug( '[Boot] Footer hook called' ) ;
444
if ( ! defined( 'LITESPEED_FOOTER_CALLED' ) ) {
445
define( 'LITESPEED_FOOTER_CALLED', true ) ;
446
}
@@ -455,22 +431,22 @@ class LiteSpeed_Cache
455
private function _check_is_html( $buffer = null )
456
{
457
if ( ! defined( 'LITESPEED_FOOTER_CALLED' ) ) {
458
- LiteSpeed_Cache_Log::debug2( '[Boot] CHK html bypass: miss footer const' ) ;
459
return ;
460
}
461
462
if ( defined( 'DOING_AJAX' ) ) {
463
- LiteSpeed_Cache_Log::debug2( '[Boot] CHK html bypass: doing ajax' ) ;
464
return ;
465
}
466
467
if ( defined( 'DOING_CRON' ) ) {
468
- LiteSpeed_Cache_Log::debug2( '[Boot] CHK html bypass: doing cron' ) ;
469
return ;
470
}
471
472
if ( $_SERVER[ 'REQUEST_METHOD' ] !== 'GET' ) {
473
- LiteSpeed_Cache_Log::debug2( '[Boot] CHK html bypass: not get method ' . $_SERVER[ 'REQUEST_METHOD' ] ) ;
474
return ;
475
}
476
@@ -489,11 +465,11 @@ class LiteSpeed_Cache
489
$is_html = stripos( $buffer, '<html' ) === 0 || stripos( $buffer, '<!DOCTYPE' ) === 0 ;
490
491
if ( ! $is_html ) {
492
- LiteSpeed_Cache_Log::debug( '[Boot] Footer check failed: ' . ob_get_level() . '-' . substr( $buffer, 0, 100 ) ) ;
493
return ;
494
}
495
496
- LiteSpeed_Cache_Log::debug( '[Boot] Footer check passed' ) ;
497
498
if ( ! defined( 'LITESPEED_IS_HTML' ) ) {
499
define( 'LITESPEED_IS_HTML', true ) ;
@@ -581,7 +557,7 @@ class LiteSpeed_Cache
581
$running_info_showing = ( defined( 'LITESPEED_IS_HTML' ) && LITESPEED_IS_HTML ) || ( defined( 'LSCACHE_IS_ESI' ) && LSCACHE_IS_ESI ) ;
582
if ( defined( 'LSCACHE_ESI_SILENCE' ) ) {
583
$running_info_showing = false ;
584
- LiteSpeed_Cache_Log::debug( '[Boot] ESI silence' ) ;
585
}
586
587
if ( $running_info_showing ) {
19
private static $_instance ;
20
21
const PLUGIN_NAME = 'litespeed-cache' ;
22
+ const PLUGIN_VERSION = '2.2' ;
23
24
const PAGE_EDIT_HTACCESS = 'lscache-edit-htaccess' ;
25
29
const ACTION_SAVE_HTACCESS = 'save-htaccess' ;
30
const ACTION_SAVE_SETTINGS = 'save-settings' ;
31
const ACTION_SAVE_SETTINGS_NETWORK = 'save-settings-network' ;
32
const ACTION_PURGE_BY = 'PURGE_BY' ;
33
const ACTION_PURGE_EMPTYCACHE = 'PURGE_EMPTYCACHE' ;
34
const ACTION_QS_PURGE = 'PURGE' ;
35
const ACTION_QS_PURGE_SINGLE = 'PURGESINGLE' ;
45
const ACTION_CDN_CLOUDFLARE = 'cdn_cloudflare' ;
46
const ACTION_CDN_QUICCLOUD = 'cdn_quiccloud' ;
47
48
const ACTION_FRONT_EXCLUDE = 'front-exclude' ;
49
50
const ACTION_DB_OPTIMIZE = 'db_optimize' ;
93
include_once LSCWP_DIR . 'thirdparty/lscwp-registry-3rd.php' ;
94
}
95
96
+ if ( self::config( LiteSpeed_Cache_Config::OPID_DEBUG_DISABLE_ALL ) ) {
97
+ define( 'LITESPEED_DISABLE_ALL', true ) ;
98
+ }
99
+
100
/**
101
* This needs to be before activation because admin-rules.class.php need const `LSCWP_CONTENT_FOLDER`
102
* @since 1.9.1 Moved up
118
// Check if there is a purge request in queue
119
if ( $purge_queue = get_option( LiteSpeed_Cache_Purge::PURGE_QUEUE ) ) {
120
@header( $purge_queue ) ;
121
+ LiteSpeed_Cache_Log::debug( '[Core] Purge Queue found&sent: ' . $purge_queue ) ;
122
delete_option( LiteSpeed_Cache_Purge::PURGE_QUEUE ) ;
123
}
124
169
// return ;
170
// }
171
172
+ if ( defined( 'LITESPEED_DISABLE_ALL' ) ) {
173
+ LiteSpeed_Cache_Log::debug( '[Core] Bypassed due to debug disable all setting' ) ;
174
+ return ;
175
+ }
176
+
177
ob_start( array( $this, 'send_headers_force' ) ) ;
178
add_action( 'shutdown', array( $this, 'send_headers' ), 0 ) ;
179
add_action( 'wp_footer', 'LiteSpeed_Cache::footer_hook' ) ;
267
$msg = __( 'Crawler blacklist is saved.', 'litespeed-cache' ) ;
268
break ;
269
270
case LiteSpeed_Cache::ACTION_QS_PURGE_ALL:
271
LiteSpeed_Cache_Purge::purge_all() ;
272
break;
273
274
case LiteSpeed_Cache::ACTION_PURGE_EMPTYCACHE:
278
$msg = __( 'Notified LiteSpeed Web Server to purge everything.', 'litespeed-cache' ) ;
279
break;
280
281
case LiteSpeed_Cache::ACTION_FRONT_EXCLUDE:
282
// redirect inside
283
LiteSpeed_Cache_Config::frontend_save() ;
416
*/
417
public static function footer_hook()
418
{
419
+ LiteSpeed_Cache_Log::debug( '[Core] Footer hook called' ) ;
420
if ( ! defined( 'LITESPEED_FOOTER_CALLED' ) ) {
421
define( 'LITESPEED_FOOTER_CALLED', true ) ;
422
}
431
private function _check_is_html( $buffer = null )
432
{
433
if ( ! defined( 'LITESPEED_FOOTER_CALLED' ) ) {
434
+ LiteSpeed_Cache_Log::debug2( '[Core] CHK html bypass: miss footer const' ) ;
435
return ;
436
}
437
438
if ( defined( 'DOING_AJAX' ) ) {
439
+ LiteSpeed_Cache_Log::debug2( '[Core] CHK html bypass: doing ajax' ) ;
440
return ;
441
}
442
443
if ( defined( 'DOING_CRON' ) ) {
444
+ LiteSpeed_Cache_Log::debug2( '[Core] CHK html bypass: doing cron' ) ;
445
return ;
446
}
447
448
if ( $_SERVER[ 'REQUEST_METHOD' ] !== 'GET' ) {
449
+ LiteSpeed_Cache_Log::debug2( '[Core] CHK html bypass: not get method ' . $_SERVER[ 'REQUEST_METHOD' ] ) ;
450
return ;
451
}
452
465
$is_html = stripos( $buffer, '<html' ) === 0 || stripos( $buffer, '<!DOCTYPE' ) === 0 ;
466
467
if ( ! $is_html ) {
468
+ LiteSpeed_Cache_Log::debug( '[Core] Footer check failed: ' . ob_get_level() . '-' . substr( $buffer, 0, 100 ) ) ;
469
return ;
470
}
471
472
+ LiteSpeed_Cache_Log::debug( '[Core] Footer check passed' ) ;
473
474
if ( ! defined( 'LITESPEED_IS_HTML' ) ) {
475
define( 'LITESPEED_IS_HTML', true ) ;
557
$running_info_showing = ( defined( 'LITESPEED_IS_HTML' ) && LITESPEED_IS_HTML ) || ( defined( 'LSCACHE_IS_ESI' ) && LSCACHE_IS_ESI ) ;
558
if ( defined( 'LSCACHE_ESI_SILENCE' ) ) {
559
$running_info_showing = false ;
560
+ LiteSpeed_Cache_Log::debug( '[Core] ESI silence' ) ;
561
}
562
563
if ( $running_info_showing ) {
inc/object.class.php CHANGED
@@ -51,7 +51,7 @@ class LiteSpeed_Cache_Object
51
*/
52
private function __construct( $cfg = false )
53
{
54
- defined( 'LSCWP_LOG' ) && LiteSpeed_Cache_Log::debug2( 'Object: init' ) ;
55
56
$this->_oc_data_file = WP_CONTENT_DIR . '/.object-cache.ini' ;
57
@@ -74,7 +74,7 @@ class LiteSpeed_Cache_Object
74
}
75
$this->_cfg_enabled = $cfg[ LiteSpeed_Cache_Config::OPID_CACHE_OBJECT ] && class_exists( $this->_oc_driver ) && $this->_cfg_host ;
76
77
- defined( 'LSCWP_LOG' ) && LiteSpeed_Cache_Log::debug( 'Object: init with cfg result : ', $this->_cfg_enabled ) ;
78
}
79
elseif ( class_exists( 'LiteSpeed_Cache' ) ) {
80
$this->_cfg_method = LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPID_CACHE_OBJECT_KIND ) ? true : false ;
@@ -174,14 +174,14 @@ class LiteSpeed_Cache_Object
174
175
// Update cls file
176
if ( ! file_exists( $wp_file ) || md5_file( $wp_file ) !== md5_file( $ori_file ) ) {
177
- defined( 'LSCWP_LOG' ) && LiteSpeed_Cache_Log::debug( 'Object: copying object-cache.php file to ' . $wp_file ) ;
178
copy( $ori_file, $wp_file ) ;
179
}
180
}
181
else {
182
// To delete file
183
if ( file_exists( $wp_file ) ) {
184
- defined( 'LSCWP_LOG' ) && LiteSpeed_Cache_Log::debug( 'Object: removing ' . $wp_file ) ;
185
unlink( $wp_file ) ;
186
}
187
file_exists( $this->_oc_data_file ) && unlink( $this->_oc_data_file ) ;
@@ -223,11 +223,11 @@ class LiteSpeed_Cache_Object
223
*/
224
public function reconnect( $cfg )
225
{
226
- defined( 'LSCWP_LOG' ) && LiteSpeed_Cache_Log::debug( 'Object: Reconnecting' ) ;
227
// error_log( 'Object: reconnect !' ) ;
228
if ( isset( $this->_conn ) ) {
229
// error_log( 'Object: Quiting existing connection!' ) ;
230
- defined( 'LSCWP_LOG' ) && LiteSpeed_Cache_Log::debug( 'Object: Quiting existing connection' ) ;
231
$this->flush() ;
232
$this->_conn = null ;
233
self::$_instance = null ;
@@ -258,7 +258,7 @@ class LiteSpeed_Cache_Object
258
return null ;
259
}
260
261
- defined( 'LSCWP_LOG' ) && LiteSpeed_Cache_Log::debug( 'Object: connecting to ' . $this->_cfg_host . ':' . $this->_cfg_port ) ;
262
263
$failed = false ;
264
/**
@@ -268,7 +268,7 @@ class LiteSpeed_Cache_Object
268
* @see https://github.com/phpredis/phpredis/#example-1
269
*/
270
if ( $this->_oc_driver == 'Redis' ) {
271
- defined( 'LSCWP_LOG' ) && LiteSpeed_Cache_Log::debug( 'Object: Init ' . $this->_oc_driver . ' connection' ) ;
272
273
set_error_handler( 'litespeed_exception_handler' ) ;
274
try {
@@ -321,18 +321,18 @@ class LiteSpeed_Cache_Object
321
* Connect to Memcached
322
*/
323
else {
324
- defined( 'LSCWP_LOG' ) && LiteSpeed_Cache_Log::debug( 'Object: Init ' . $this->_oc_driver . ' connection' ) ;
325
if ( $this->_cfg_persistent ) {
326
$this->_conn = new Memcached( $this->_get_mem_id() ) ;
327
328
// Check memcached persistent connection
329
if ( $this->_validate_mem_server() ) {
330
// error_log( 'Object: _validate_mem_server' ) ;
331
- defined( 'LSCWP_LOG' ) && LiteSpeed_Cache_Log::debug( 'Object: Got persistent ' . $this->_oc_driver . ' connection' ) ;
332
return true ;
333
}
334
335
- defined( 'LSCWP_LOG' ) && LiteSpeed_Cache_Log::debug( 'Object: No persistent ' . $this->_oc_driver . ' server list!' ) ;
336
}
337
else {
338
// error_log( 'Object: new memcached!' ) ;
@@ -357,14 +357,14 @@ class LiteSpeed_Cache_Object
357
358
// If failed to connect
359
if ( $failed ) {
360
- defined( 'LSCWP_LOG' ) && LiteSpeed_Cache_Log::debug( 'Object: Failed to connect ' . $this->_oc_driver . ' server!' ) ;
361
$this->_conn = null ;
362
$this->_cfg_enabled = false ;
363
// error_log( 'Object: false!' ) ;
364
return false ;
365
}
366
367
- defined( 'LSCWP_LOG' ) && LiteSpeed_Cache_Log::debug2( 'Object: Connected' ) ;
368
369
return true ;
370
}
@@ -430,7 +430,7 @@ class LiteSpeed_Cache_Object
430
return null ;
431
}
432
433
- // defined( 'LSCWP_LOG' ) && LiteSpeed_Cache_Log::debug2( 'Object: get ' . $key ) ;
434
435
$res = $this->_conn->get( $key ) ;
436
@@ -457,7 +457,7 @@ class LiteSpeed_Cache_Object
457
return null ;
458
}
459
460
- // defined( 'LSCWP_LOG' ) && LiteSpeed_Cache_Log::debug2( 'Object: set ' . $key ) ;
461
462
// error_log( 'Object: set ' . $key ) ;
463
@@ -503,7 +503,7 @@ class LiteSpeed_Cache_Object
503
return null ;
504
}
505
506
- // defined( 'LSCWP_LOG' ) && LiteSpeed_Cache_Log::debug2( 'Object: delete ' . $key ) ;
507
508
$res = $this->_conn->delete( $key ) ;
509
@@ -519,7 +519,7 @@ class LiteSpeed_Cache_Object
519
public function flush()
520
{
521
if ( ! $this->_cfg_enabled ) {
522
- defined( 'LSCWP_LOG' ) && LiteSpeed_Cache_Log::debug( 'Object: bypass flushing' ) ;
523
return null ;
524
}
525
@@ -527,7 +527,7 @@ class LiteSpeed_Cache_Object
527
return null ;
528
}
529
530
- defined( 'LSCWP_LOG' ) && LiteSpeed_Cache_Log::debug( 'Object: flush!' ) ;
531
532
if ( $this->_oc_driver == 'Redis' ) {
533
$res = $this->_conn->flushDb() ;
51
*/
52
private function __construct( $cfg = false )
53
{
54
+ defined( 'LSCWP_LOG' ) && LiteSpeed_Cache_Log::debug2( '[Object] init' ) ;
55
56
$this->_oc_data_file = WP_CONTENT_DIR . '/.object-cache.ini' ;
57
74
}
75
$this->_cfg_enabled = $cfg[ LiteSpeed_Cache_Config::OPID_CACHE_OBJECT ] && class_exists( $this->_oc_driver ) && $this->_cfg_host ;
76
77
+ defined( 'LSCWP_LOG' ) && LiteSpeed_Cache_Log::debug( '[Object] init with cfg result : ', $this->_cfg_enabled ) ;
78
}
79
elseif ( class_exists( 'LiteSpeed_Cache' ) ) {
80
$this->_cfg_method = LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPID_CACHE_OBJECT_KIND ) ? true : false ;
174
175
// Update cls file
176
if ( ! file_exists( $wp_file ) || md5_file( $wp_file ) !== md5_file( $ori_file ) ) {
177
+ defined( 'LSCWP_LOG' ) && LiteSpeed_Cache_Log::debug( '[Object] copying object-cache.php file to ' . $wp_file ) ;
178
copy( $ori_file, $wp_file ) ;
179
}
180
}
181
else {
182
// To delete file
183
if ( file_exists( $wp_file ) ) {
184
+ defined( 'LSCWP_LOG' ) && LiteSpeed_Cache_Log::debug( '[Object] removing ' . $wp_file ) ;
185
unlink( $wp_file ) ;
186
}
187
file_exists( $this->_oc_data_file ) && unlink( $this->_oc_data_file ) ;
223
*/
224
public function reconnect( $cfg )
225
{
226
+ defined( 'LSCWP_LOG' ) && LiteSpeed_Cache_Log::debug( '[Object] Reconnecting' ) ;
227
// error_log( 'Object: reconnect !' ) ;
228
if ( isset( $this->_conn ) ) {
229
// error_log( 'Object: Quiting existing connection!' ) ;
230
+ defined( 'LSCWP_LOG' ) && LiteSpeed_Cache_Log::debug( '[Object] Quiting existing connection' ) ;
231
$this->flush() ;
232
$this->_conn = null ;
233
self::$_instance = null ;
258
return null ;
259
}
260
261
+ defined( 'LSCWP_LOG' ) && LiteSpeed_Cache_Log::debug( '[Object] connecting to ' . $this->_cfg_host . ':' . $this->_cfg_port ) ;
262
263
$failed = false ;
264
/**
268
* @see https://github.com/phpredis/phpredis/#example-1
269
*/
270
if ( $this->_oc_driver == 'Redis' ) {
271
+ defined( 'LSCWP_LOG' ) && LiteSpeed_Cache_Log::debug( '[Object] Init ' . $this->_oc_driver . ' connection' ) ;
272
273
set_error_handler( 'litespeed_exception_handler' ) ;
274
try {
321
* Connect to Memcached
322
*/
323
else {
324
+ defined( 'LSCWP_LOG' ) && LiteSpeed_Cache_Log::debug( '[Object] Init ' . $this->_oc_driver . ' connection' ) ;
325
if ( $this->_cfg_persistent ) {
326
$this->_conn = new Memcached( $this->_get_mem_id() ) ;
327
328
// Check memcached persistent connection
329
if ( $this->_validate_mem_server() ) {
330
// error_log( 'Object: _validate_mem_server' ) ;
331
+ defined( 'LSCWP_LOG' ) && LiteSpeed_Cache_Log::debug( '[Object] Got persistent ' . $this->_oc_driver . ' connection' ) ;
332
return true ;
333
}
334
335
+ defined( 'LSCWP_LOG' ) && LiteSpeed_Cache_Log::debug( '[Object] No persistent ' . $this->_oc_driver . ' server list!' ) ;
336
}
337
else {
338
// error_log( 'Object: new memcached!' ) ;
357
358
// If failed to connect
359
if ( $failed ) {
360
+ defined( 'LSCWP_LOG' ) && LiteSpeed_Cache_Log::debug( '[Object] Failed to connect ' . $this->_oc_driver . ' server!' ) ;
361
$this->_conn = null ;
362
$this->_cfg_enabled = false ;
363
// error_log( 'Object: false!' ) ;
364
return false ;
365
}
366
367
+ defined( 'LSCWP_LOG' ) && LiteSpeed_Cache_Log::debug2( '[Object] Connected' ) ;
368
369
return true ;
370
}
430
return null ;
431
}
432
433
+ // defined( 'LSCWP_LOG' ) && LiteSpeed_Cache_Log::debug2( '[Object] get ' . $key ) ;
434
435
$res = $this->_conn->get( $key ) ;
436
457
return null ;
458
}
459
460
+ // defined( 'LSCWP_LOG' ) && LiteSpeed_Cache_Log::debug2( '[Object] set ' . $key ) ;
461
462
// error_log( 'Object: set ' . $key ) ;
463
503
return null ;
504
}
505
506
+ // defined( 'LSCWP_LOG' ) && LiteSpeed_Cache_Log::debug2( '[Object] delete ' . $key ) ;
507
508
$res = $this->_conn->delete( $key ) ;
509
519
public function flush()
520
{
521
if ( ! $this->_cfg_enabled ) {
522
+ defined( 'LSCWP_LOG' ) && LiteSpeed_Cache_Log::debug( '[Object] bypass flushing' ) ;
523
return null ;
524
}
525
527
return null ;
528
}
529
530
+ defined( 'LSCWP_LOG' ) && LiteSpeed_Cache_Log::debug( '[Object] flush!' ) ;
531
532
if ( $this->_oc_driver == 'Redis' ) {
533
$res = $this->_conn->flushDb() ;
inc/optimize.class.php CHANGED
@@ -367,7 +367,7 @@ class LiteSpeed_Cache_Optimize
367
// Check if hit URI excludes
368
$excludes = LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPID_OPTM_EXCLUDES ) ;
369
if ( ! empty( $excludes ) ) {
370
- $result = LiteSpeed_Cache_Utility::str_hit_array( esc_url( $_SERVER[ 'REQUEST_URI' ] ), explode( "\n", $excludes ) ) ;
371
if ( $result ) {
372
LiteSpeed_Cache_Log::debug( '[Optm] bypass: hit URI Excludes setting: ' . $result ) ;
373
return $content ;
367
// Check if hit URI excludes
368
$excludes = LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPID_OPTM_EXCLUDES ) ;
369
if ( ! empty( $excludes ) ) {
370
+ $result = LiteSpeed_Cache_Utility::str_hit_array( $_SERVER[ 'REQUEST_URI' ], explode( "\n", $excludes ) ) ;
371
if ( $result ) {
372
LiteSpeed_Cache_Log::debug( '[Optm] bypass: hit URI Excludes setting: ' . $result ) ;
373
return $content ;
inc/purge.class.php CHANGED
@@ -4,6 +4,7 @@
4
*
5
* @since 1.1.3
6
* @since 1.5 Moved into /inc
7
* @package LiteSpeed_Cache
8
* @subpackage LiteSpeed_Cache/inc
9
* @author LiteSpeed Technologies <info@litespeedtech.com>
@@ -11,16 +12,24 @@
11
class LiteSpeed_Cache_Purge
12
{
13
private static $_instance ;
14
- protected static $_pub_purge = array() ;
15
- protected static $_priv_purge = array() ;
16
- protected static $_purge_related = false ;
17
- protected static $_purge_single = false ;
18
19
const X_HEADER = 'X-LiteSpeed-Purge' ;
20
const PURGE_QUEUE = 'litespeed-cache-purge-queue' ;
21
22
- const TYPE_OBJECT_PURGE_ALL = 'object_purge_all' ;
23
- const TYPE_OPCACHE_PURGE_ALL = 'opcache_purge_all' ;
24
25
/**
26
* Handle all request actions from main cls
@@ -35,12 +44,40 @@ class LiteSpeed_Cache_Purge
35
$type = LiteSpeed_Cache_Router::verify_type() ;
36
37
switch ( $type ) {
38
- case self::TYPE_OBJECT_PURGE_ALL :
39
- $instance->_object_purge_all() ;
40
break ;
41
42
- case self::TYPE_OPCACHE_PURGE_ALL :
43
- $instance->_opcache_purge_all() ;
44
break ;
45
46
default:
@@ -50,29 +87,106 @@ class LiteSpeed_Cache_Purge
50
LiteSpeed_Cache_Admin::redirect() ;
51
}
52
53
/**
54
* Purge opcode cache
55
*
56
* @since 1.8.2
57
* @access private
58
*/
59
- private function _opcache_purge_all()
60
{
61
if ( ! LiteSpeed_Cache_Router::opcache_enabled() ) {
62
- LiteSpeed_Cache_Log::debug( 'Purge: Failed to reset opcode cache due to opcache not enabled' ) ;
63
64
- $msg = __( 'Opcode cache is not enabled.', 'litespeed-cache' ) ;
65
- LiteSpeed_Cache_Admin_Display::error( $msg ) ;
66
67
return false ;
68
}
69
70
// Purge opcode cache
71
opcache_reset() ;
72
- LiteSpeed_Cache_Log::debug( 'Purge: Reset opcode cache' ) ;
73
74
- $msg = __( 'Reset the entire opcode cache successfully.', 'litespeed-cache' ) ;
75
- LiteSpeed_Cache_Admin_Display::succeed( $msg ) ;
76
77
return true ;
78
}
@@ -83,21 +197,25 @@ class LiteSpeed_Cache_Purge
83
* @since 1.8
84
* @access private
85
*/
86
- private function _object_purge_all()
87
{
88
if ( ! defined( 'LSCWP_OBJECT_CACHE' ) ) {
89
- LiteSpeed_Cache_Log::debug( 'Purge: Failed to flush object cache due to object cache not enabled' ) ;
90
91
- $msg = __( 'Object cache is not enabled.', 'litespeed-cache' ) ;
92
- LiteSpeed_Cache_Admin_Display::error( $msg ) ;
93
94
return false ;
95
}
96
LiteSpeed_Cache_Object::get_instance()->flush() ;
97
- LiteSpeed_Cache_Log::debug( 'Purge: Flushed object cache' ) ;
98
99
- $msg = __( 'Purge all object caches successfully.', 'litespeed-cache' ) ;
100
- LiteSpeed_Cache_Admin_Display::succeed( $msg ) ;
101
102
return true ;
103
}
@@ -110,28 +228,40 @@ class LiteSpeed_Cache_Purge
110
* @param mixed $tags Tags to add to the list.
111
*/
112
public static function add( $tags )
113
{
114
if ( ! is_array( $tags ) ) {
115
$tags = array( $tags ) ;
116
}
117
- if ( ! array_diff( $tags, self::$_pub_purge ) ) {
118
return ;
119
}
120
121
- self::$_pub_purge = array_merge( self::$_pub_purge, $tags ) ;
122
- LiteSpeed_Cache_Log::debug( 'Purge: added ' . implode( ',', $tags ), 3 ) ;
123
124
// Send purge header immediately
125
- $curr_built = self::_build() ;
126
if ( defined( 'LITESPEED_DID_send_headers' ) ) {
127
// Can't send, already has output, need to save and wait for next run
128
update_option( self::PURGE_QUEUE, $curr_built ) ;
129
- LiteSpeed_Cache_Log::debug( 'Output existed, Purge queue stored: ' . $curr_built ) ;
130
}
131
else {
132
@header( $curr_built ) ;
133
LiteSpeed_Cache_Log::debug( $curr_built ) ;
134
}
135
}
136
137
/**
@@ -142,20 +272,31 @@ class LiteSpeed_Cache_Purge
142
* @param mixed $tags Tags to add to the list.
143
*/
144
public static function add_private( $tags )
145
{
146
if ( ! is_array( $tags ) ) {
147
$tags = array( $tags ) ;
148
}
149
- if ( ! array_diff( $tags, self::$_priv_purge ) ) {
150
return ;
151
}
152
153
- LiteSpeed_Cache_Log::debug( 'Purge: added [private] ' . implode( ',', $tags ), 3 ) ;
154
155
- self::$_priv_purge = array_merge( self::$_priv_purge, $tags ) ;
156
157
// Send purge header immediately
158
- @header( self::_build() ) ;
159
}
160
161
/**
@@ -166,7 +307,7 @@ class LiteSpeed_Cache_Purge
166
*/
167
public static function set_purge_related()
168
{
169
- self::$_purge_related = true ;
170
}
171
172
/**
@@ -177,94 +318,89 @@ class LiteSpeed_Cache_Purge
177
*/
178
public static function set_purge_single()
179
{
180
- self::$_purge_single = true ;
181
}
182
183
/**
184
- * Check qs purge status
185
*
186
- * @since 1.1.3
187
* @access public
188
*/
189
- public static function get_qs_purge()
190
{
191
- return self::$_purge_single || self::$_purge_related ;
192
}
193
194
/**
195
- * Alerts LiteSpeed Web Server to purge all pages.
196
- *
197
- * For multisite installs, if this is called by a site admin (not network admin),
198
- * it will only purge all posts associated with that site.
199
*
200
- * @since 1.0.0
201
- * @access public
202
*/
203
- public static function purge_all()
204
{
205
- self::add( '*' ) ;
206
-
207
- // check if need to reset crawler
208
- if ( LiteSpeed_Cache::config( LiteSpeed_Cache_Config::CRWL_CRON_ACTIVE ) ) {
209
- LiteSpeed_Cache_Crawler::get_instance()->reset_pos() ;
210
}
211
}
212
213
/**
214
* Alerts LiteSpeed Web Server to purge the front page.
215
*
216
* @since 1.0.3
217
- * @access public
218
*/
219
- public static function purge_front()
220
{
221
- self::add( LiteSpeed_Cache_Tag::TYPE_FRONTPAGE ) ;
222
if ( LITESPEED_SERVER_TYPE !== 'LITESPEED_SERVER_OLS' ) {
223
- self::add_private( LiteSpeed_Cache_Tag::TYPE_FRONTPAGE ) ;
224
}
225
- }
226
227
- /**
228
- * Alerts LiteSpeed Web Server to purge pages.
229
- *
230
- * @since 1.0.15
231
- * @access public
232
- */
233
- public static function purge_pages()
234
- {
235
- self::add( LiteSpeed_Cache_Tag::TYPE_PAGES ) ;
236
}
237
238
/**
239
* Alerts LiteSpeed Web Server to purge pages.
240
*
241
- * @since 1.2.2
242
- * @access public
243
*/
244
- public static function purge_cssjs()
245
{
246
- self::add( LiteSpeed_Cache_Tag::TYPE_MIN ) ;
247
248
- // For non-ls users
249
- LiteSpeed_Cache_Optimize::get_instance()->rm_cache_folder() ;
250
}
251
252
/**
253
* Alerts LiteSpeed Web Server to purge error pages.
254
*
255
* @since 1.0.14
256
- * @access public
257
*/
258
- public static function purge_errors()
259
{
260
- self::add( LiteSpeed_Cache_Tag::TYPE_ERROR ) ;
261
262
- $type = LiteSpeed_Cache_Router::verify_type() ;
263
if ( ! $type || ! in_array( $type, array( '403', '404', '500' ) ) ) {
264
return ;
265
}
266
267
- self::add( LiteSpeed_Cache_Tag::TYPE_ERROR . $type ) ;
268
}
269
270
/**
@@ -291,9 +427,9 @@ class LiteSpeed_Cache_Purge
291
return ;
292
}
293
294
- LiteSpeed_Cache_Admin_Display::add_notice( LiteSpeed_Cache_Admin_Display::NOTICE_GREEN, sprintf( __( 'Purge category %s', 'litespeed-cache' ), $val ) ) ;
295
296
- self::add( LiteSpeed_Cache_Tag::TYPE_ARCHIVE_TERM . $cat->term_id ) ;
297
}
298
299
/**
@@ -318,9 +454,9 @@ class LiteSpeed_Cache_Purge
318
LiteSpeed_Cache_Admin_Display::add_error( LiteSpeed_Cache_Admin_Error::E_PURGEBY_PID_DNE, $val ) ;
319
return ;
320
}
321
- LiteSpeed_Cache_Admin_Display::add_notice( LiteSpeed_Cache_Admin_Display::NOTICE_GREEN, sprintf( __( 'Purge Post ID %s', 'litespeed-cache' ), $val ) ) ;
322
323
- self::add( LiteSpeed_Cache_Tag::TYPE_POST . $val ) ;
324
}
325
326
/**
@@ -347,9 +483,9 @@ class LiteSpeed_Cache_Purge
347
return ;
348
}
349
350
- LiteSpeed_Cache_Admin_Display::add_notice( LiteSpeed_Cache_Admin_Display::NOTICE_GREEN, sprintf( __( 'Purge tag %s', 'litespeed-cache' ), $val ) ) ;
351
352
- self::add( LiteSpeed_Cache_Tag::TYPE_ARCHIVE_TERM . $term->term_id ) ;
353
}
354
355
/**
@@ -381,9 +517,9 @@ class LiteSpeed_Cache_Purge
381
return ;
382
}
383
384
- LiteSpeed_Cache_Admin_Display::add_notice( LiteSpeed_Cache_Admin_Display::NOTICE_GREEN, sprintf( __( 'Purge url %s', 'litespeed-cache' ), $val ) ) ;
385
386
- self::add( $hash ) ;
387
return ;
388
}
389
@@ -425,29 +561,10 @@ class LiteSpeed_Cache_Purge
425
LiteSpeed_Cache_Admin_Display::add_error(LiteSpeed_Cache_Admin_Error::E_PURGEBY_BAD) ;
426
return ;
427
}
428
- array_walk($list, Array($this, $cb)) ;
429
430
// for redirection
431
- $_GET[LiteSpeed_Cache_Admin_Display::PURGEBYOPT_SELECT] = $sel ;
432
- }
433
-
434
- /**
435
- * Purge frontend url
436
- *
437
- * @since 1.3
438
- * @access public
439
- */
440
- public static function frontend_purge()
441
- {
442
- if ( empty( $_SERVER[ 'HTTP_REFERER' ] ) ) {
443
- exit( 'no referer' ) ;
444
- }
445
- $instance = self::get_instance() ;
446
-
447
- $instance->purgeby_url_cb( $_SERVER[ 'HTTP_REFERER' ] ) ;
448
-
449
- wp_redirect( $_SERVER[ 'HTTP_REFERER' ] ) ;
450
- exit() ;
451
}
452
453
/**
@@ -468,17 +585,19 @@ class LiteSpeed_Cache_Purge
468
return ;
469
}
470
471
- $purge_tags = self::get_purge_tags_by_post($post_id) ;
472
if ( empty($purge_tags) ) {
473
return ;
474
}
475
if ( in_array( '*', $purge_tags ) ) {
476
- self::purge_all() ;
477
}
478
else {
479
- self::add( $purge_tags ) ;
480
if ( LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPID_CACHE_REST ) ) {
481
- self::add( LiteSpeed_Cache_Tag::TYPE_REST ) ;
482
}
483
}
484
LiteSpeed_Cache_Control::set_stale() ;
@@ -553,7 +672,7 @@ class LiteSpeed_Cache_Purge
553
* @access private
554
* @since 1.1.3
555
*/
556
- private static function _finalize()
557
{
558
// Make sure header output only run once
559
if ( ! defined( 'LITESPEED_DID_' . __FUNCTION__ ) ) {
@@ -566,26 +685,26 @@ class LiteSpeed_Cache_Purge
566
do_action('litespeed_cache_api_purge') ;
567
568
// Append unique uri purge tags if Admin QS is `PURGESINGLE`
569
- if ( self::$_purge_single ) {
570
- self::$_pub_purge[] = LiteSpeed_Cache_Tag::build_uri_tag() ; // TODO: add private tag too
571
}
572
// Append related purge tags if Admin QS is `PURGE`
573
- if ( self::$_purge_related ) {
574
// Before this, tags need to be finalized
575
$tags_related = LiteSpeed_Cache_Tag::output_tags() ;
576
// NOTE: need to remove the empty item `B1_` to avoid purging all
577
$tags_related = array_filter($tags_related) ;
578
if ( $tags_related ) {
579
- self::$_pub_purge = array_merge(self::$_pub_purge, $tags_related) ;
580
}
581
}
582
583
- if ( ! empty(self::$_pub_purge) ) {
584
- self::$_pub_purge = array_unique(self::$_pub_purge) ;
585
}
586
587
- if ( ! empty(self::$_priv_purge) ) {
588
- self::$_priv_purge = array_unique(self::$_priv_purge) ;
589
}
590
}
591
@@ -600,9 +719,11 @@ class LiteSpeed_Cache_Purge
600
*/
601
public static function output()
602
{
603
- self::_finalize() ;
604
605
- return self::_build() ;
606
}
607
608
/**
@@ -612,17 +733,17 @@ class LiteSpeed_Cache_Purge
612
* @access private
613
* @return string the built purge header
614
*/
615
- private static function _build()
616
{
617
- if ( empty( self::$_pub_purge ) && empty( self::$_priv_purge ) ) {
618
return ;
619
}
620
621
$purge_header = '' ;
622
$private_prefix = self::X_HEADER . ': private,' ;
623
624
- if ( ! empty( self::$_pub_purge ) ) {
625
- $public_tags = self::_append_prefix( self::$_pub_purge ) ;
626
if ( empty( $public_tags ) ) {
627
// If this ends up empty, private will also end up empty
628
return ;
@@ -636,8 +757,8 @@ class LiteSpeed_Cache_Purge
636
}
637
638
// Handle priv purge tags
639
- if ( ! empty( self::$_priv_purge ) ) {
640
- $private_tags = self::_append_prefix( self::$_priv_purge, true ) ;
641
$purge_header .= $private_prefix . implode( ',', $private_tags ) ;
642
}
643
@@ -653,7 +774,7 @@ class LiteSpeed_Cache_Purge
653
* @param boolean $is_private If is private tags or not.
654
* @return array The array of built purge tags.
655
*/
656
- private static function _append_prefix( $purge_tags, $is_private = false )
657
{
658
$curr_bid = get_current_blog_id() ;
659
@@ -676,7 +797,7 @@ class LiteSpeed_Cache_Purge
676
)) ) {
677
$blogs = LiteSpeed_Cache_Activation::get_network_ids() ;
678
if ( empty($blogs) ) {
679
- LiteSpeed_Cache_Log::debug('build_purge_headers: blog list is empty') ;
680
return '' ;
681
}
682
$tags = array() ;
@@ -699,11 +820,11 @@ class LiteSpeed_Cache_Purge
699
* any third party plugin specific post tags.
700
*
701
* @since 1.0.0
702
- * @access public
703
* @param integer $post_id The id of the post about to be purged.
704
* @return array The list of purge tags correlated with the post.
705
*/
706
- public static function get_purge_tags_by_post( $post_id )
707
{
708
// If this is a valid post we want to purge the post, the home page and any associated tags & cats
709
// If not, purge everything on the site.
@@ -836,7 +957,7 @@ class LiteSpeed_Cache_Purge
836
*/
837
public static function get_instance()
838
{
839
- if ( ! isset(self::$_instance) ) {
840
self::$_instance = new self() ;
841
}
842
4
*
5
* @since 1.1.3
6
* @since 1.5 Moved into /inc
7
+ * @since 2.2 Refactored. Changed access from public to private for most func and class variables.
8
* @package LiteSpeed_Cache
9
* @subpackage LiteSpeed_Cache/inc
10
* @author LiteSpeed Technologies <info@litespeedtech.com>
12
class LiteSpeed_Cache_Purge
13
{
14
private static $_instance ;
15
+ protected $_pub_purge = array() ;
16
+ protected $_priv_purge = array() ;
17
+ protected $_purge_related = false ;
18
+ protected $_purge_single = false ;
19
20
const X_HEADER = 'X-LiteSpeed-Purge' ;
21
const PURGE_QUEUE = 'litespeed-cache-purge-queue' ;
22
23
+ const TYPE_PURGE_ALL = 'purge_all' ;
24
+ const TYPE_PURGE_ALL_LSCACHE = 'purge_all_lscache' ;
25
+ const TYPE_PURGE_ALL_CSSJS = 'purge_all_cssjs' ;
26
+ const TYPE_PURGE_ALL_OBJECT = 'purge_all_object' ;
27
+ const TYPE_PURGE_ALL_OPCACHE = 'purge_all_opcache' ;
28
+
29
+ const TYPE_PURGE_FRONT = 'purge_front' ;
30
+ const TYPE_PURGE_FRONTPAGE = 'purge_frontpage' ;
31
+ const TYPE_PURGE_PAGES = 'purge_pages' ;
32
+ const TYPE_PURGE_ERROR = 'purge_error' ;
33
34
/**
35
* Handle all request actions from main cls
44
$type = LiteSpeed_Cache_Router::verify_type() ;
45
46
switch ( $type ) {
47
+ case self::TYPE_PURGE_ALL :
48
+ $instance->_purge_all() ;
49
+ break ;
50
+
51
+ case self::TYPE_PURGE_ALL_LSCACHE :
52
+ $instance->_purge_all_lscache() ;
53
+ break ;
54
+
55
+ case self::TYPE_PURGE_ALL_CSSJS :
56
+ $instance->_purge_all_cssjs() ;
57
break ;
58
59
+ case self::TYPE_PURGE_ALL_OBJECT :
60
+ $instance->_purge_all_object() ;
61
+ break ;
62
+
63
+ case self::TYPE_PURGE_ALL_OPCACHE :
64
+ $instance->_purge_all_opcache() ;
65
+ break ;
66
+
67
+ case self::TYPE_PURGE_FRONT :
68
+ $instance->_purge_front() ;
69
+ break ;
70
+
71
+ case self::TYPE_PURGE_FRONTPAGE :
72
+ $instance->_purge_frontpage() ;
73
+ break ;
74
+
75
+ case self::TYPE_PURGE_PAGES :
76
+ $instance->_purge_pages() ;
77
+ break ;
78
+
79
+ case strpos( $type, self::TYPE_PURGE_ERROR ) === 0 :
80
+ $instance->_purge_error( substr( $type, strlen( self::TYPE_PURGE_ERROR ) ) ) ;
81
break ;
82
83
default:
87
LiteSpeed_Cache_Admin::redirect() ;
88
}
89
90
+ /**
91
+ * Shortcut to purge all lscache
92
+ *
93
+ * @since 1.0.0
94
+ * @access public
95
+ */
96
+ public static function purge_all( $reason = false )
97
+ {
98
+ self::get_instance()->_purge_all( $reason ) ;
99
+ }
100
+
101
+ /**
102
+ * Purge all caches (lscache/op/oc)
103
+ *
104
+ * @since 2.2
105
+ * @access private
106
+ */
107
+ private function _purge_all( $reason = false )
108
+ {
109
+ $this->_purge_all_lscache( true ) ;
110
+ $this->_purge_all_cssjs( true ) ;
111
+ $this->_purge_all_object( true ) ;
112
+ $this->_purge_all_opcache( true ) ;
113
+
114
+ LiteSpeed_Cache_Log::debug( '[Purge] Purge all' . ( $reason ? ' [Reason] ' . $reason : '' ), 3 ) ;
115
+
116
+ $msg = __( 'Purge all caches successfully.', 'litespeed-cache' ) ;
117
+ LiteSpeed_Cache_Admin_Display::succeed( $msg ) ;
118
+ }
119
+
120
+ /**
121
+ * Alerts LiteSpeed Web Server to purge all pages.
122
+ *
123
+ * For multisite installs, if this is called by a site admin (not network admin),
124
+ * it will only purge all posts associated with that site.
125
+ *
126
+ * @since 2.2
127
+ * @access public
128
+ */
129
+ private function _purge_all_lscache( $silence = false )
130
+ {
131
+ $this->_add( '*' ) ;
132
+
133
+ // check if need to reset crawler
134
+ if ( LiteSpeed_Cache::config( LiteSpeed_Cache_Config::CRWL_CRON_ACTIVE ) ) {
135
+ LiteSpeed_Cache_Crawler::get_instance()->reset_pos() ;
136
+ }
137
+
138
+ if ( ! $silence ) {
139
+ $msg = __( 'Notified LiteSpeed Web Server to purge all LSCache entries.', 'litespeed-cache' ) ;
140
+ LiteSpeed_Cache_Admin_Display::succeed( $msg ) ;
141
+ }
142
+ }
143
+
144
+ /**
145
+ * Alerts LiteSpeed Web Server to purge pages.
146
+ *
147
+ * @since 1.2.2
148
+ * @access private
149
+ */
150
+ private function _purge_all_cssjs( $silence = false )
151
+ {
152
+ $this->_add( LiteSpeed_Cache_Tag::TYPE_MIN ) ;
153
+
154
+ // For non-ls users
155
+ LiteSpeed_Cache_Optimize::get_instance()->rm_cache_folder() ;
156
+
157
+ if ( ! $silence ) {
158
+ $msg = __( 'Notified LiteSpeed Web Server to purge CSS/JS entries.', 'litespeed-cache' ) ;
159
+ LiteSpeed_Cache_Admin_Display::succeed( $msg ) ;
160
+ }
161
+ }
162
+
163
/**
164
* Purge opcode cache
165
*
166
* @since 1.8.2
167
* @access private
168
*/
169
+ private function _purge_all_opcache( $silence = false )
170
{
171
if ( ! LiteSpeed_Cache_Router::opcache_enabled() ) {
172
+ LiteSpeed_Cache_Log::debug( '[Purge] Failed to reset opcode cache due to opcache not enabled' ) ;
173
174
+ if ( ! $silence ) {
175
+ $msg = __( 'Opcode cache is not enabled.', 'litespeed-cache' ) ;
176
+ LiteSpeed_Cache_Admin_Display::error( $msg ) ;
177
+ }
178
179
return false ;
180
}
181
182
// Purge opcode cache
183
opcache_reset() ;
184
+ LiteSpeed_Cache_Log::debug( '[Purge] Reset opcode cache' ) ;
185
186
+ if ( ! $silence ) {
187
+ $msg = __( 'Reset the entire opcode cache successfully.', 'litespeed-cache' ) ;
188
+ LiteSpeed_Cache_Admin_Display::succeed( $msg ) ;
189
+ }
190
191
return true ;
192
}
197
* @since 1.8
198
* @access private
199
*/
200
+ private function _purge_all_object( $silence = false )
201
{
202
if ( ! defined( 'LSCWP_OBJECT_CACHE' ) ) {
203
+ LiteSpeed_Cache_Log::debug( '[Purge] Failed to flush object cache due to object cache not enabled' ) ;
204
205
+ if ( ! $silence ) {
206
+ $msg = __( 'Object cache is not enabled.', 'litespeed-cache' ) ;
207
+ LiteSpeed_Cache_Admin_Display::error( $msg ) ;
208
+ }
209
210
return false ;
211
}
212
LiteSpeed_Cache_Object::get_instance()->flush() ;
213
+ LiteSpeed_Cache_Log::debug( '[Purge] Flushed object cache' ) ;
214
215
+ if ( ! $silence ) {
216
+ $msg = __( 'Purge all object caches successfully.', 'litespeed-cache' ) ;
217
+ LiteSpeed_Cache_Admin_Display::succeed( $msg ) ;
218
+ }
219
220
return true ;
221
}
228
* @param mixed $tags Tags to add to the list.
229
*/
230
public static function add( $tags )
231
+ {
232
+ self::get_instance()->_add( $tags ) ;
233
+ }
234
+
235
+ /**
236
+ * Add tags to purge
237
+ *
238
+ * @since 2.2
239
+ * @access private
240
+ */
241
+ private function _add( $tags )
242
{
243
if ( ! is_array( $tags ) ) {
244
$tags = array( $tags ) ;
245
}
246
+ if ( ! array_diff( $tags, $this->_pub_purge ) ) {
247
return ;
248
}
249
250
+ $this->_pub_purge = array_merge( $this->_pub_purge, $tags ) ;
251
+ LiteSpeed_Cache_Log::debug( '[Purge] added ' . implode( ',', $tags ), 3 ) ;
252
253
// Send purge header immediately
254
+ $curr_built = $this->_build() ;
255
if ( defined( 'LITESPEED_DID_send_headers' ) ) {
256
// Can't send, already has output, need to save and wait for next run
257
update_option( self::PURGE_QUEUE, $curr_built ) ;
258
+ LiteSpeed_Cache_Log::debug( '[Purge] Output existed, queue stored: ' . $curr_built ) ;
259
}
260
else {
261
@header( $curr_built ) ;
262
LiteSpeed_Cache_Log::debug( $curr_built ) ;
263
}
264
+
265
}
266
267
/**
272
* @param mixed $tags Tags to add to the list.
273
*/
274
public static function add_private( $tags )
275
+ {
276
+ self::get_instance()->_add_private( $tags ) ;
277
+ }
278
+
279
+ /**
280
+ * Add tags to private purge
281
+ *
282
+ * @since 2.2
283
+ * @access private
284
+ */
285
+ private function _add_private( $tags )
286
{
287
if ( ! is_array( $tags ) ) {
288
$tags = array( $tags ) ;
289
}
290
+ if ( ! array_diff( $tags, $this->_priv_purge ) ) {
291
return ;
292
}
293
294
+ LiteSpeed_Cache_Log::debug( '[Purge] added [private] ' . implode( ',', $tags ), 3 ) ;
295
296
+ $this->_priv_purge = array_merge( $this->_priv_purge, $tags ) ;
297
298
// Send purge header immediately
299
+ @header( $this->_build() ) ;
300
}
301
302
/**
307
*/
308
public static function set_purge_related()
309
{
310
+ self::get_instance()->_purge_related = true ;
311
}
312
313
/**
318
*/
319
public static function set_purge_single()
320
{
321
+ self::get_instance()->_purge_single = true ;
322
}
323
324
/**
325
+ * Called from cfg::frontend_save() to purge front page
326
*
327
+ * @since 2.2
328
* @access public
329
*/
330
+ public static function purge_front()
331
{
332
+ self::get_instance()->_purge_front() ;
333
}
334
335
/**
336
+ * Purge frontend url
337
*
338
+ * @since 1.3
339
+ * @since 2.2 Renamed from `frontend_purge`; Access changed from public
340
+ * @access private
341
*/
342
+ private function _purge_front()
343
{
344
+ if ( empty( $_SERVER[ 'HTTP_REFERER' ] ) ) {
345
+ exit( 'no referer' ) ;
346
}
347
+
348
+ $this->purgeby_url_cb( $_SERVER[ 'HTTP_REFERER' ] ) ;
349
+
350
+ wp_redirect( $_SERVER[ 'HTTP_REFERER' ] ) ;
351
+ exit() ;
352
}
353
354
/**
355
* Alerts LiteSpeed Web Server to purge the front page.
356
*
357
* @since 1.0.3
358
+ * @since 2.2 Access changed from public to private, renamed from `_purge_front`
359
+ * @access private
360
*/
361
+ private function _purge_frontpage()
362
{
363
+ $this->_add( LiteSpeed_Cache_Tag::TYPE_FRONTPAGE ) ;
364
if ( LITESPEED_SERVER_TYPE !== 'LITESPEED_SERVER_OLS' ) {
365
+ $this->_add_private( LiteSpeed_Cache_Tag::TYPE_FRONTPAGE ) ;
366
}
367
368
+ $msg = __( 'Notified LiteSpeed Web Server to purge the front page.', 'litespeed-cache' ) ;
369
+ LiteSpeed_Cache_Admin_Display::succeed( $msg ) ;
370
}
371
372
/**
373
* Alerts LiteSpeed Web Server to purge pages.
374
*
375
+ * @since 1.0.15
376
+ * @access private
377
*/
378
+ private function _purge_pages()
379
{
380
+ $this->_add( LiteSpeed_Cache_Tag::TYPE_PAGES ) ;
381
382
+ $msg = __( 'Notified LiteSpeed Web Server to purge pages.', 'litespeed-cache' ) ;
383
+ LiteSpeed_Cache_Admin_Display::succeed( $msg ) ;
384
}
385
386
/**
387
* Alerts LiteSpeed Web Server to purge error pages.
388
*
389
* @since 1.0.14
390
+ * @access private
391
*/
392
+ private function _purge_error( $type = false )
393
{
394
+ $this->_add( LiteSpeed_Cache_Tag::TYPE_ERROR ) ;
395
396
if ( ! $type || ! in_array( $type, array( '403', '404', '500' ) ) ) {
397
return ;
398
}
399
400
+ $this->_add( LiteSpeed_Cache_Tag::TYPE_ERROR . $type ) ;
401
+
402
+ $msg = __( 'Notified LiteSpeed Web Server to purge error pages.', 'litespeed-cache' ) ;
403
+ LiteSpeed_Cache_Admin_Display::succeed( $msg ) ;
404
}
405
406
/**
427
return ;
428
}
429
430
+ LiteSpeed_Cache_Admin_Display::succeed( sprintf( __( 'Purge category %s', 'litespeed-cache' ), $val ) ) ;
431
432
+ $this->_add( LiteSpeed_Cache_Tag::TYPE_ARCHIVE_TERM . $cat->term_id ) ;
433
}
434
435
/**
454
LiteSpeed_Cache_Admin_Display::add_error( LiteSpeed_Cache_Admin_Error::E_PURGEBY_PID_DNE, $val ) ;
455
return ;
456
}
457
+ LiteSpeed_Cache_Admin_Display::succeed( sprintf( __( 'Purge Post ID %s', 'litespeed-cache' ), $val ) ) ;
458
459
+ $this->_add( LiteSpeed_Cache_Tag::TYPE_POST . $val ) ;
460
}
461
462
/**
483
return ;
484
}
485
486
+ LiteSpeed_Cache_Admin_Display::succeed( sprintf( __( 'Purge tag %s', 'litespeed-cache' ), $val ) ) ;
487
488
+ $this->_add( LiteSpeed_Cache_Tag::TYPE_ARCHIVE_TERM . $term->term_id ) ;
489
}
490
491
/**
517
return ;
518
}
519
520
+ LiteSpeed_Cache_Admin_Display::succeed( sprintf( __( 'Purge url %s', 'litespeed-cache' ), $val ) ) ;
521
522
+ $this->_add( $hash ) ;
523
return ;
524
}
525
561
LiteSpeed_Cache_Admin_Display::add_error(LiteSpeed_Cache_Admin_Error::E_PURGEBY_BAD) ;
562
return ;
563
}
564
+ array_walk( $list, array( $this, $cb ) ) ;
565
566
// for redirection
567
+ $_GET[ LiteSpeed_Cache_Admin_Display::PURGEBYOPT_SELECT ] = $sel ;
568
}
569
570
/**
585
return ;
586
}
587
588
+ $instance = self::get_instance() ;
589
+
590
+ $purge_tags = $instance->_get_purge_tags_by_post($post_id) ;
591
if ( empty($purge_tags) ) {
592
return ;
593
}
594
if ( in_array( '*', $purge_tags ) ) {
595
+ $instance->_purge_all_lscache() ;
596
}
597
else {
598
+ $instance->_add( $purge_tags ) ;
599
if ( LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPID_CACHE_REST ) ) {
600
+ $instance->_add( LiteSpeed_Cache_Tag::TYPE_REST ) ;
601
}
602
}
603
LiteSpeed_Cache_Control::set_stale() ;
672
* @access private
673
* @since 1.1.3
674
*/
675
+ private function _finalize()
676
{
677
// Make sure header output only run once
678
if ( ! defined( 'LITESPEED_DID_' . __FUNCTION__ ) ) {
685
do_action('litespeed_cache_api_purge') ;
686
687
// Append unique uri purge tags if Admin QS is `PURGESINGLE`
688
+ if ( $this->_purge_single ) {
689
+ $this->_pub_purge[] = LiteSpeed_Cache_Tag::build_uri_tag() ; // TODO: add private tag too
690
}
691
// Append related purge tags if Admin QS is `PURGE`
692
+ if ( $this->_purge_related ) {
693
// Before this, tags need to be finalized
694
$tags_related = LiteSpeed_Cache_Tag::output_tags() ;
695
// NOTE: need to remove the empty item `B1_` to avoid purging all
696
$tags_related = array_filter($tags_related) ;
697
if ( $tags_related ) {
698
+ $this->_pub_purge = array_merge($this->_pub_purge, $tags_related) ;
699
}
700
}
701
702
+ if ( ! empty($this->_pub_purge) ) {
703
+ $this->_pub_purge = array_unique($this->_pub_purge) ;
704
}
705
706
+ if ( ! empty($this->_priv_purge) ) {
707
+ $this->_priv_purge = array_unique($this->_priv_purge) ;
708
}
709
}
710
719
*/
720
public static function output()
721
{
722
+ $instance = self::get_instance() ;
723
+
724
+ $instance->_finalize() ;
725
726
+ return $instance->_build() ;
727
}
728
729
/**
733
* @access private
734
* @return string the built purge header
735
*/
736
+ private function _build()
737
{
738
+ if ( empty( $this->_pub_purge ) && empty( $this->_priv_purge ) ) {
739
return ;
740
}
741
742
$purge_header = '' ;
743
$private_prefix = self::X_HEADER . ': private,' ;
744
745
+ if ( ! empty( $this->_pub_purge ) ) {
746
+ $public_tags = $this->_append_prefix( $this->_pub_purge ) ;
747
if ( empty( $public_tags ) ) {
748
// If this ends up empty, private will also end up empty
749
return ;
757
}
758
759
// Handle priv purge tags
760
+ if ( ! empty( $this->_priv_purge ) ) {
761
+ $private_tags = $this->_append_prefix( $this->_priv_purge, true ) ;
762
$purge_header .= $private_prefix . implode( ',', $private_tags ) ;
763
}
764
774
* @param boolean $is_private If is private tags or not.
775
* @return array The array of built purge tags.
776
*/
777
+ private function _append_prefix( $purge_tags, $is_private = false )
778
{
779
$curr_bid = get_current_blog_id() ;
780
797
)) ) {
798
$blogs = LiteSpeed_Cache_Activation::get_network_ids() ;
799
if ( empty($blogs) ) {
800
+ LiteSpeed_Cache_Log::debug('[Purge] build_purge_headers: blog list is empty') ;
801
return '' ;
802
}
803
$tags = array() ;
820
* any third party plugin specific post tags.
821
*
822
* @since 1.0.0
823
+ * @access private
824
* @param integer $post_id The id of the post about to be purged.
825
* @return array The list of purge tags correlated with the post.
826
*/
827
+ private function _get_purge_tags_by_post( $post_id )
828
{
829
// If this is a valid post we want to purge the post, the home page and any associated tags & cats
830
// If not, purge everything on the site.
957
*/
958
public static function get_instance()
959
{
960
+ if ( ! isset( self::$_instance ) ) {
961
self::$_instance = new self() ;
962
}
963
inc/router.class.php CHANGED
@@ -346,31 +346,20 @@ class LiteSpeed_Cache_Router
346
}
347
return ;
348
349
- case LiteSpeed_Cache::ACTION_PURGE_FRONT:
350
- case LiteSpeed_Cache::ACTION_PURGE_PAGES:
351
- case LiteSpeed_Cache::ACTION_PURGE_ERRORS:
352
- case LiteSpeed_Cache::ACTION_PURGE_ALL:
353
case LiteSpeed_Cache::ACTION_PURGE_BY:
354
- case LiteSpeed_Cache::ACTION_FRONT_PURGE:
355
case LiteSpeed_Cache::ACTION_FRONT_EXCLUDE:
356
if ( defined( 'LITESPEED_ON' ) && ( $_can_network_option || $_can_option || self::is_ajax() ) ) {//here may need more security
357
self::$_action = $action ;
358
}
359
return ;
360
361
- case LiteSpeed_Cache::ACTION_PURGE_CSSJS: // will clear non-ls users file-based cache folder too
362
- if ( $_can_network_option || $_can_option || self::is_ajax() ) {
363
- self::$_action = $action ;
364
- }
365
- return ;
366
-
367
case LiteSpeed_Cache::ACTION_DB_OPTIMIZE:
368
if ( $_can_network_option || $_can_option ) {
369
self::$_action = $action ;
370
}
371
return ;
372
373
- case LiteSpeed_Cache::ACTION_PURGE_EMPTYCACHE:
374
if ( defined( 'LITESPEED_ON' ) && ( $_can_network_option || ( ! $_is_multisite && $_can_option ) ) ) {
375
self::$_action = $action ;
376
}
346
}
347
return ;
348
349
case LiteSpeed_Cache::ACTION_PURGE_BY:
350
case LiteSpeed_Cache::ACTION_FRONT_EXCLUDE:
351
if ( defined( 'LITESPEED_ON' ) && ( $_can_network_option || $_can_option || self::is_ajax() ) ) {//here may need more security
352
self::$_action = $action ;
353
}
354
return ;
355
356
case LiteSpeed_Cache::ACTION_DB_OPTIMIZE:
357
if ( $_can_network_option || $_can_option ) {
358
self::$_action = $action ;
359
}
360
return ;
361
362
+ case LiteSpeed_Cache::ACTION_PURGE_EMPTYCACHE:// todo: moved to purge.cls type action
363
if ( defined( 'LITESPEED_ON' ) && ( $_can_network_option || ( ! $_is_multisite && $_can_option ) ) ) {
364
self::$_action = $action ;
365
}
includes/litespeed-cache-api.class.php CHANGED
@@ -114,6 +114,28 @@ class LiteSpeed_Cache_API
114
LiteSpeed_Cache_Control::set_nocache( $reason ?: 'api' ) ;
115
}
116
117
/**
118
* Get current not cacheable status
119
*
114
LiteSpeed_Cache_Control::set_nocache( $reason ?: 'api' ) ;
115
}
116
117
+ /**
118
+ * Set cache status to cacheable ( By default cacheable status will be set when called WP hook `wp` )
119
+ *
120
+ * @since 2.2
121
+ * @access public
122
+ */
123
+ public static function set_cacheable( $reason )
124
+ {
125
+ LiteSpeed_Cache_Control::set_cacheable( $reason ) ;
126
+ }
127
+
128
+ /**
129
+ * Set cache status to force cacheable ( Will ignore most kinds of non-cacheable conditions )
130
+ *
131
+ * @since 2.2
132
+ * @access public
133
+ */
134
+ public static function set_force_cacheable( $reason )
135
+ {
136
+ LiteSpeed_Cache_Control::force_cacheable( $reason ) ;
137
+ }
138
+
139
/**
140
* Get current not cacheable status
141
*
includes/litespeed-cache-config.class.php CHANGED
@@ -95,6 +95,7 @@ class LiteSpeed_Cache_Config
95
// do NOT set default options for these three, it is used for admin.
96
const ID_NOCACHE_COOKIES = 'nocache_cookies' ;
97
const ID_NOCACHE_USERAGENTS = 'nocache_useragents' ;