Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Purge - keep guest pages #623

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions data/const.default.ini
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ purge-upgrade = true
; O_PURGE_STALE
purge-stale = false

purge-skip_guest_pages = false
purge-post_all = false
purge-post_f = true
purge-post_h = true
Expand Down
2 changes: 2 additions & 0 deletions src/base.cls.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class Base extends Root
## -------------- Purge ----------------- ##
## -------------------------------------------------- ##
const O_PURGE_ON_UPGRADE = 'purge-upgrade';
const O_PURGE_SKIP_GUEST_PAGES = 'purge-skip_guest_pages';
const O_PURGE_STALE = 'purge-stale';
const O_PURGE_POST_ALL = 'purge-post_all';
const O_PURGE_POST_FRONTPAGE = 'purge-post_f';
Expand Down Expand Up @@ -373,6 +374,7 @@ class Base extends Root

// Purge
self::O_PURGE_ON_UPGRADE => false,
self::O_PURGE_SKIP_GUEST_PAGES => false,
self::O_PURGE_STALE => false,
self::O_PURGE_POST_ALL => false,
self::O_PURGE_POST_FRONTPAGE => false,
Expand Down
1 change: 1 addition & 0 deletions src/lang.cls.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ public static function title($id)
self::O_OBJECT_TRANSIENTS => __('Store Transients', 'litespeed-cache'),

self::O_PURGE_ON_UPGRADE => __('Purge All On Upgrade', 'litespeed-cache'),
self::O_PURGE_SKIP_GUEST_PAGES => __('Skip Guest Mode Pages on Purge All', 'litespeed-cache'),
self::O_PURGE_STALE => __('Serve Stale', 'litespeed-cache'),
self::O_PURGE_TIMED_URLS => __('Scheduled Purge URLs', 'litespeed-cache'),
self::O_PURGE_TIMED_URLS_TIME => __('Scheduled Purge Time', 'litespeed-cache'),
Expand Down
8 changes: 7 additions & 1 deletion src/purge.cls.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,13 @@ private function _purge_all($reason = false)
*/
private function _purge_all_lscache($silence = false)
{
$this->_add('*');
$tags = ['*'];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't work for PHP5.3

$skip_purge_guest = $this->conf(BASE::O_PURGE_SKIP_GUEST_PAGES);
if ($skip_purge_guest) {
$tags = ['non-guest'];
}

$this->_add($tags, false);

if (!$silence) {
$msg = __('Notified LiteSpeed Web Server to purge all LSCache entries.', 'litespeed-cache');
Expand Down
10 changes: 9 additions & 1 deletion src/tag.cls.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,10 @@ private static function _build_type_tags()
return $tags;
}

private static function _is_visitor_guest(){
return !is_user_logged_in();
}

/**
* Generate all cache tags before output
*
Expand All @@ -328,9 +332,13 @@ private static function _finalize()
self::$_tags = array_merge(self::$_tags, $type_tags);
}

if (defined('LITESPEED_GUEST') && LITESPEED_GUEST) {
if((defined('LITESPEED_GUEST') && LITESPEED_GUEST) || (self::cls()->conf(BASE::O_GUEST) && self::_is_visitor_guest())){
self::$_tags[] = 'guest';
}

if((defined('LITESPEED_GUEST') && !LITESPEED_GUEST) || !self::_is_visitor_guest()){
self::$_tags[] = 'non-guest';
}

// append blog main tag
self::$_tags[] = '';
Expand Down
10 changes: 10 additions & 0 deletions tpl/cache/settings-purge.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@
<?php require LSCWP_DIR . 'tpl/cache/settings_inc.purge_on_upgrade.tpl.php'; ?>
<?php endif; ?>

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

<tr>
<th><?php echo __( 'Auto Purge Rules For Publish/Update', 'litespeed-cache' ); ?></th>
<td>
Expand Down
Loading