LSCache - How to prevent specified pages from being cached

Has anyone tried deleting specific pages from the LS cache?

For example, in the Varnish cache I can delete using “^/user/” for example, or “/user/”, just insert this into the Varnish controller.

Or for example, in CloudPanel:

How could I do this in WEbAdmin?

I’ve tried a few things here but it doesn’t seem to work as expected. HTACCESS rules do not delete the specific pages that I want to provide without the cache.

Has anyone tried something like this?

Hello @pryce

Go to wp-admin/admin.php?page=litespeed-cache#excludes to achieve this. You can list the URIs here, one per line. Partial URIs are fine. They will be compared to the REQUEST_URI server variable, and excluded from cache if a match is found.

When listing URIs, it’s best to include as much of the string as possible, so that you don’t inadvertantly match more URIs to the string than intended. You can also narrow it down further with the special characters ^ and $ . To indicate the beginning of a URI, add ^ to the beginning of the string. To do an exact match, add $ to the end of the string.

Assume your site consists of only the following URIs:

  1. /recipes/baking/
  2. /recipes/baking/cakes
  3. /recipes/baking/brownies
  4. /popular/recipes/baking/

The string /recipes/baking/ will match all four URIs.

The string cakes will only match #2.

The string /recipes/baking/$ will only match #1 (because $ indicates exact match).

The string ^/recipes/baking will match #1, #2, and #3 (because ^ indicates the beginning of the URI).

1 Like

Hi Joseph, thank you so much for sharing this option for WordPress.

For use on WordPress sites it looks perfect and should work fine. :slight_smile:

But, I am trying to apply OpenLiteSpeed caching on standard php websites with option to exclude certain pages. I already tried some ways here but I don’t see a solution.

Can you tell if there isn’t an option to apply caching for php sites or applications other than standard WordPress?

In CloudPanel I can apply Varnish to any installation, I’m understanding a little more about caching and I realize that this is essential to optimize applications, I can easily do this in cloudpanel, however, I’ve been trying in cyberpanel through OLS, but I still I was not successful with deleting specific pages.

For example, if I enable caching in OLS, it applies caching without exception to the entire site or application, and this is bad for some applications that have data updated in real time.

I would need to prevent caching in some pages and areas of the application, but I don’t see how to assertively enable these exclusions.

In fact, I see all the options here and I can’t assimilate a way to do this, maybe I don’t even have one.

I can apply caching to everything, but I would like to set some exceptions, and it doesn’t seem to work.

The only recommended method is using rewirte rules or .htaccess but a server level configuration is required for OLS/LS by turning the caching egine on via vHost config at server level(recommended) or per website (preferred by me because it gives more control and isolation)

<IfModule Litespeed>
CacheEngine on
CacheRoot lscache
CacheLookup public on
</IfModule>

https://www.litespeedtech.com/support/wiki/doku.php/litespeed_wiki:cache:common_installation:apache-config-shared

Then to preventspecific pages from cache using rewrite rules

<IfModule LiteSpeed> 
RewriteEngine On
RewriteRule  admin/(.*\.php)?$ - [E=Cache-Control:no-cache]
</IfModule> 

Or use private cache to tell LSCACHE to cache specific locations

example here only caches requests if they meet all of the following criteria:

  • They are HEAD or GET type requests
  • They don’t contain cookiename in the HTTP_COOKIE
  • %{ORG_REQ_URI} does not start with /administrator/
# LiteSpeed rules for private cache
<IfModule LiteSpeed>
RewriteCond %{REQUEST_METHOD} ^HEAD|GET$
RewriteCond %{HTTP_COOKIE} loginuser
RewriteCond %{ORG_REQ_URI} !^/index\.php$
RewriteRule .* - [E=Cache-Control:private]
</IfModule>

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index.php
RewriteCond %{REQUEST_URI} (/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$  [NC]
RewriteRule (.*) index.php [L]

Hi, I already tried settings in htaccess, the problem is that my application has no file extension, it is a mod application of laravel base framework.

There was an example in the documentation that I made and it worked, but it slowed down my application.

But you suggested something that might work, I can configure more specific rules using the private cache option that you suggested, I think that way I will have more control and I can understand where the conflict is.

Is it possible in the future that the cyberpanel team will be able to automate OLS configuration processes directly from the CP panel? I see that many configurations, some even indispensable, still need to be manually configured. This can be tricky to keep stable when you have multiple applications on the same server, despite OLS having an isolated vhost option.

For example, Varnish cache is a bit complex too, but it was amazing how the CloudPanel team made deployment and configuration so easy, with a few clicks you integrate Varnish cache into any application, that was genius, not even in cPanel I see something as simple as that. I found out about this option a little while ago and I’m loving it, but I’m still in doubt which one to use, that’s why I’m doing comparisons and one of these comparison steps is precisely the cache configuration.

I’ll give it a try and update here on further results. :slight_smile:

Thanks Joseph.