Skip to content

Commit 968512e

Browse files
author
Hai Zheng
committed
v6.3-b1: * 🌱**Cache** Cache POST requests. Now can configure POST/GET AJAX requests to be cached. (#647300)
1 parent 2e5eca3 commit 968512e

7 files changed

+26
-47
lines changed

‎litespeed-cache.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Plugin Name: LiteSpeed Cache
55
* Plugin URI: https://www.litespeedtech.com/products/cache-plugins/wordpress-acceleration
66
* Description: High-performance page caching and site optimization from LiteSpeed
7-
* Version: 6.3-a3
7+
* Version: 6.3-b1
88
* Author: LiteSpeed Technologies
99
* Author URI: https://www.litespeedtech.com
1010
* License: GPLv3
@@ -34,7 +34,7 @@
3434
return;
3535
}
3636

37-
!defined('LSCWP_V') && define('LSCWP_V', '6.3-a3');
37+
!defined('LSCWP_V') && define('LSCWP_V', '6.3-b1');
3838

3939
!defined('LSCWP_CONTENT_DIR') && define('LSCWP_CONTENT_DIR', WP_CONTENT_DIR);
4040
!defined('LSCWP_DIR') && define('LSCWP_DIR', __DIR__ . '/'); // Full absolute path '/var/www/html/***/wp-content/plugins/litespeed-cache/' or MU

‎readme.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,10 +251,11 @@ The vast majority of plugins and themes are compatible with LiteSpeed Cache. The
251251
== Changelog ==
252252

253253
= 6.3 - Jun 2024 =
254-
* 🌱**Page Optimize** New option: HTML Keep Comments. (#328853)
255-
* **CLoud** Fixed an message error for daily quota.
254+
* 🌱**Page Optimize** HTML Keep Comments. (#328853)
255+
* 🌱**Cache** Cache POST requests. Now can configure POST/GET AJAX requests to be cached. (#647300)
256256
* **Cache** Bypassed admin initialization when doing ajax call. (Tim)
257257
* **Cache** Better control over the cache location #541 (Gal Baras/Tanvir Israq)
258+
* **CLoud** Fixed an message error for daily quota.
258259
* **ESI** Bypassed ESI at early stage when getting `DONOTCACHEPAGE`.
259260
* **ESI** Added ESI nonce for Events Calendar and Mobile hamburger menu - jetMenu. (#306983 #163710 PR#419)
260261
* **ESI** Added WP Data Access nonce (PR#665)

‎src/base.cls.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class Base extends Root
6363
const O_CACHE_TTL_REST = 'cache-ttl_rest';
6464
const O_CACHE_TTL_STATUS = 'cache-ttl_status';
6565
const O_CACHE_TTL_BROWSER = 'cache-ttl_browser';
66-
const O_CACHE_POST_TTL = 'cache-post_ttl';
66+
const O_CACHE_AJAX_TTL = 'cache-ajax_ttl';
6767
const O_CACHE_LOGIN_COOKIE = 'cache-login_cookie';
6868
const O_CACHE_VARY_COOKIES = 'cache-vary_cookies';
6969
const O_CACHE_VARY_GROUP = 'cache-vary_group';
@@ -367,7 +367,7 @@ class Base extends Root
367367
self::O_CACHE_TTL_BROWSER => 0,
368368
self::O_CACHE_TTL_STATUS => array(),
369369
self::O_CACHE_LOGIN_COOKIE => '',
370-
self::O_CACHE_POST_TTL => array(),
370+
self::O_CACHE_AJAX_TTL => array(),
371371
self::O_CACHE_VARY_COOKIES => array(),
372372
self::O_CACHE_VARY_GROUP => array(),
373373

‎src/control.cls.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,20 @@ public function init_cacheable()
134134
}
135135
}
136136

137+
// AJAX cache
138+
$ajax_cache = $this->conf(Base::O_CACHE_AJAX_TTL);
139+
foreach ($ajax_cache as $v) {
140+
$v = explode(' ', $v);
141+
if (empty($v[0]) || empty($v[1])) {
142+
continue;
143+
}
144+
// self::debug("Initializing cacheable status for wp_ajax_nopriv_" . $v[0]);
145+
add_action("wp_ajax_nopriv_" . $v[0], function () use ($v) {
146+
self::set_custom_ttl($v[1]);
147+
self::force_cacheable("ajax Cache setting for action " . $v[0]);
148+
}, 4);
149+
}
150+
137151
// Check error page
138152
add_filter('status_header', array($this, 'check_error_codes'), 10, 2);
139153
}

‎src/core.cls.php

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -375,41 +375,6 @@ public function proceed_action($action)
375375
*/
376376
public function load_thirdparty()
377377
{
378-
add_action('wp_ajax_my_ajax_action', function () {
379-
$response = array(
380-
'message' => 'AJAX time ' . date('Y-m-d H:i:s'),
381-
);
382-
wp_send_json_success($response);
383-
});
384-
add_action('wp_ajax_nopriv_my_ajax_action', function () {
385-
$response = array(
386-
'message' => 'AJAX time ' . date('Y-m-d H:i:s'),
387-
);
388-
wp_send_json_success($response);
389-
});
390-
add_action('wp_enqueue_scripts', function () {
391-
wp_enqueue_script('jquery');
392-
wp_add_inline_script('jquery', 'var ajaxurl = "' . admin_url('admin-ajax.php') . '";');
393-
});
394-
add_filter('litespeed_buffer_finalize', function ($body) {
395-
return str_replace(
396-
'</html>',
397-
"<script>
398-
jQuery.ajax({
399-
url: ajaxurl,
400-
type: 'GET',
401-
data: {
402-
action: 'llllll_action',
403-
},
404-
success: function(response) {
405-
console.log(response);
406-
},
407-
});
408-
</script></html>",
409-
$body
410-
);
411-
});
412-
413378
do_action('litespeed_load_thirdparty');
414379
}
415380

‎src/lang.cls.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ public static function maybe_translate($raw_string)
4646
{
4747
$map = array(
4848
'auto_alias_failed_cdn' =>
49-
__('Unable to automatically add %1$s as a Domain Alias for main %2$s domain, due to potential CDN conflict.', 'litespeed-cache') .
49+
__('Unable to automatically add %1$s as a Domain Alias for main %2$s domain, due to potential CDN conflict.', 'litespeed-cache') .
5050
' ' .
5151
Doc::learn_more('https://quic.cloud/docs/cdn/dns/how-to-setup-domain-alias/', false, false, false, true),
5252

5353
'auto_alias_failed_uid' =>
54-
__('Unable to automatically add %1$s as a Domain Alias for main %2$s domain.', 'litespeed-cache') .
54+
__('Unable to automatically add %1$s as a Domain Alias for main %2$s domain.', 'litespeed-cache') .
5555
' ' .
5656
__('Alias is in use by another QUIC.cloud account.', 'litespeed-cache') .
5757
' ' .
@@ -100,7 +100,7 @@ public static function title($id)
100100
self::O_CACHE_TTL_REST => __('Default REST TTL', 'litespeed-cache'),
101101
self::O_CACHE_TTL_STATUS => __('Default HTTP Status Code Page TTL', 'litespeed-cache'),
102102
self::O_CACHE_TTL_BROWSER => __('Browser Cache TTL', 'litespeed-cache'),
103-
self::O_CACHE_POST_TTL => __('POST Cache TTL', 'litespeed-cache'),
103+
self::O_CACHE_AJAX_TTL => __('AJAX Cache TTL', 'litespeed-cache'),
104104
self::O_AUTO_UPGRADE => __('Automatically Upgrade', 'litespeed-cache'),
105105
self::O_GUEST => __('Guest Mode', 'litespeed-cache'),
106106
self::O_GUEST_OPTM => __('Guest Optimization', 'litespeed-cache'),

‎tpl/cache/settings-advanced.tpl.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,17 @@
2020

2121
<tr>
2222
<th>
23-
<?php $id = Base::O_CACHE_POST_TTL; ?>
23+
<?php $id = Base::O_CACHE_AJAX_TTL; ?>
2424
<?php $this->title($id); ?>
2525
</th>
2626
<td>
27-
2827
<div class="litespeed-textarea-recommended">
2928
<div>
3029
<?php $this->build_textarea($id, 60); ?>
3130
</div>
3231
</div>
3332
<div class="litespeed-desc">
34-
<?php echo __('Specify an AJAX action in POST and the number of seconds to cache that request, separated by a space.', 'litespeed-cache'); ?>
33+
<?php echo __('Specify an AJAX action in POST/GET and the number of seconds to cache that request, separated by a space.', 'litespeed-cache'); ?>
3534
<?php Doc::one_per_line(); ?>
3635
</div>
3736
</td>

0 commit comments

Comments
 (0)