Skip to content

Commit

Permalink
v6.3-b1: * 🌱**Cache** Cache POST requests. Now can configure POST/GET…
Browse files Browse the repository at this point in the history
… AJAX requests to be cached. (#647300)
  • Loading branch information
Hai Zheng committed Jun 11, 2024
1 parent 2e5eca3 commit 968512e
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 47 deletions.
4 changes: 2 additions & 2 deletions litespeed-cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Plugin Name: LiteSpeed Cache
* Plugin URI: https://www.litespeedtech.com/products/cache-plugins/wordpress-acceleration
* Description: High-performance page caching and site optimization from LiteSpeed
* Version: 6.3-a3
* Version: 6.3-b1
* Author: LiteSpeed Technologies
* Author URI: https://www.litespeedtech.com
* License: GPLv3
Expand Down Expand Up @@ -34,7 +34,7 @@
return;
}

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

!defined('LSCWP_CONTENT_DIR') && define('LSCWP_CONTENT_DIR', WP_CONTENT_DIR);
!defined('LSCWP_DIR') && define('LSCWP_DIR', __DIR__ . '/'); // Full absolute path '/var/www/html/***/wp-content/plugins/litespeed-cache/' or MU
Expand Down
5 changes: 3 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,11 @@ The vast majority of plugins and themes are compatible with LiteSpeed Cache. The
== Changelog ==

= 6.3 - Jun 2024 =
* 🌱**Page Optimize** New option: HTML Keep Comments. (#328853)
* **CLoud** Fixed an message error for daily quota.
* 🌱**Page Optimize** HTML Keep Comments. (#328853)
* 🌱**Cache** Cache POST requests. Now can configure POST/GET AJAX requests to be cached. (#647300)
* **Cache** Bypassed admin initialization when doing ajax call. (Tim)
* **Cache** Better control over the cache location #541 (Gal Baras/Tanvir Israq)
* **CLoud** Fixed an message error for daily quota.
* **ESI** Bypassed ESI at early stage when getting `DONOTCACHEPAGE`.
* **ESI** Added ESI nonce for Events Calendar and Mobile hamburger menu - jetMenu. (#306983 #163710 PR#419)
* **ESI** Added WP Data Access nonce (PR#665)
Expand Down
4 changes: 2 additions & 2 deletions src/base.cls.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Base extends Root
const O_CACHE_TTL_REST = 'cache-ttl_rest';
const O_CACHE_TTL_STATUS = 'cache-ttl_status';
const O_CACHE_TTL_BROWSER = 'cache-ttl_browser';
const O_CACHE_POST_TTL = 'cache-post_ttl';
const O_CACHE_AJAX_TTL = 'cache-ajax_ttl';
const O_CACHE_LOGIN_COOKIE = 'cache-login_cookie';
const O_CACHE_VARY_COOKIES = 'cache-vary_cookies';
const O_CACHE_VARY_GROUP = 'cache-vary_group';
Expand Down Expand Up @@ -367,7 +367,7 @@ class Base extends Root
self::O_CACHE_TTL_BROWSER => 0,
self::O_CACHE_TTL_STATUS => array(),
self::O_CACHE_LOGIN_COOKIE => '',
self::O_CACHE_POST_TTL => array(),
self::O_CACHE_AJAX_TTL => array(),
self::O_CACHE_VARY_COOKIES => array(),
self::O_CACHE_VARY_GROUP => array(),

Expand Down
14 changes: 14 additions & 0 deletions src/control.cls.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,20 @@ public function init_cacheable()
}
}

// AJAX cache
$ajax_cache = $this->conf(Base::O_CACHE_AJAX_TTL);
foreach ($ajax_cache as $v) {
$v = explode(' ', $v);
if (empty($v[0]) || empty($v[1])) {
continue;
}
// self::debug("Initializing cacheable status for wp_ajax_nopriv_" . $v[0]);
add_action("wp_ajax_nopriv_" . $v[0], function () use ($v) {
self::set_custom_ttl($v[1]);
self::force_cacheable("ajax Cache setting for action " . $v[0]);
}, 4);
}

// Check error page
add_filter('status_header', array($this, 'check_error_codes'), 10, 2);
}
Expand Down
35 changes: 0 additions & 35 deletions src/core.cls.php
Original file line number Diff line number Diff line change
Expand Up @@ -375,41 +375,6 @@ public function proceed_action($action)
*/
public function load_thirdparty()
{
add_action('wp_ajax_my_ajax_action', function () {
$response = array(
'message' => 'AJAX time ' . date('Y-m-d H:i:s'),
);
wp_send_json_success($response);
});
add_action('wp_ajax_nopriv_my_ajax_action', function () {
$response = array(
'message' => 'AJAX time ' . date('Y-m-d H:i:s'),
);
wp_send_json_success($response);
});
add_action('wp_enqueue_scripts', function () {
wp_enqueue_script('jquery');
wp_add_inline_script('jquery', 'var ajaxurl = "' . admin_url('admin-ajax.php') . '";');
});
add_filter('litespeed_buffer_finalize', function ($body) {
return str_replace(
'</html>',
"<script>
jQuery.ajax({
url: ajaxurl,
type: 'GET',
data: {
action: 'llllll_action',
},
success: function(response) {
console.log(response);
},
});
</script></html>",
$body
);
});

do_action('litespeed_load_thirdparty');
}

Expand Down
6 changes: 3 additions & 3 deletions src/lang.cls.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ public static function maybe_translate($raw_string)
{
$map = array(
'auto_alias_failed_cdn' =>
__('Unable to automatically add %1$s as a Domain Alias for main %2$s domain, due to potential CDN conflict.', 'litespeed-cache') .
__('Unable to automatically add %1$s as a Domain Alias for main %2$s domain, due to potential CDN conflict.', 'litespeed-cache') .
' ' .
Doc::learn_more('https://quic.cloud/docs/cdn/dns/how-to-setup-domain-alias/', false, false, false, true),

'auto_alias_failed_uid' =>
__('Unable to automatically add %1$s as a Domain Alias for main %2$s domain.', 'litespeed-cache') .
__('Unable to automatically add %1$s as a Domain Alias for main %2$s domain.', 'litespeed-cache') .
' ' .
__('Alias is in use by another QUIC.cloud account.', 'litespeed-cache') .
' ' .
Expand Down Expand Up @@ -100,7 +100,7 @@ public static function title($id)
self::O_CACHE_TTL_REST => __('Default REST TTL', 'litespeed-cache'),
self::O_CACHE_TTL_STATUS => __('Default HTTP Status Code Page TTL', 'litespeed-cache'),
self::O_CACHE_TTL_BROWSER => __('Browser Cache TTL', 'litespeed-cache'),
self::O_CACHE_POST_TTL => __('POST Cache TTL', 'litespeed-cache'),
self::O_CACHE_AJAX_TTL => __('AJAX Cache TTL', 'litespeed-cache'),
self::O_AUTO_UPGRADE => __('Automatically Upgrade', 'litespeed-cache'),
self::O_GUEST => __('Guest Mode', 'litespeed-cache'),
self::O_GUEST_OPTM => __('Guest Optimization', 'litespeed-cache'),
Expand Down
5 changes: 2 additions & 3 deletions tpl/cache/settings-advanced.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,17 @@

<tr>
<th>
<?php $id = Base::O_CACHE_POST_TTL; ?>
<?php $id = Base::O_CACHE_AJAX_TTL; ?>
<?php $this->title($id); ?>
</th>
<td>

<div class="litespeed-textarea-recommended">
<div>
<?php $this->build_textarea($id, 60); ?>
</div>
</div>
<div class="litespeed-desc">
<?php echo __('Specify an AJAX action in POST and the number of seconds to cache that request, separated by a space.', 'litespeed-cache'); ?>
<?php echo __('Specify an AJAX action in POST/GET and the number of seconds to cache that request, separated by a space.', 'litespeed-cache'); ?>
<?php Doc::one_per_line(); ?>
</div>
</td>
Expand Down

0 comments on commit 968512e

Please sign in to comment.