This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
litespeed_wiki:cache:no-plugin-advanced:purge [2019/07/02 13:50]
Lisa Clarke [Procedures]
litespeed_wiki:cache:no-plugin-advanced:purge [2020/09/23 20:44] (current)
Lisa Clarke Redirect to new Documentation Site
Line 1: Line 1:
-====== Purging LSCache Without a Plugin ====== +~~REDIRECT>https://docs.litespeedtech.com/lscache/basics/~~
-If you are using a LiteSpeed Cache plugin, then you should not have to worry about manually purging the cache when content changes on your site. The plugin is meant to handle such situations automatically. Additionally,​ there is usually a "​Purge"​ button available if manual management is required. We strongly recommend using a plugin if it is available. Check our [[litespeed_wiki:​cache#​lscache_plugins_by_application|List of LSCache plugins]] to see if one is available for your application. +
- +
-If there is no plugin for your application,​ and you are using LiteSpeed Cache [[litespeed_wiki:​cache:​no-plugin-setup-guidline|with rewrite rules]], then you may find purging to be a challenge. +
- +
-This is how LSCache works when you are using it without a plugin:  +
- +
-Everything is cached. Some URLs or particular conditions may be excluded, but by default everything is cached for a short period of time (for instance, two minutes). After that time, the cache expires and pages will need to be re-cached again. If any content changes befor the cache expires, the page will not be purged. Changes will not be reflected in the frontend until the cache expires naturally. +
- +
-This kind of delay is fine for many cases, particularly if the cache expiration TTL is set to a very short time. However, if your TTL is very long, or if an urgent update cannot wait for the cache to expire, a mechanism for purging the cache is necessary. **As of LiteSpeed Web Server v4.1.12, a cache PURGE operation is supported** to accommodate cache manipulation on demand. +
- +
-===== Procedures ===== +
- +
-Let's assume you've set up rewrite rules like the following in .htaccess:​ +
-<code <​IfModule LiteSpeed>​ +
-  RewriteEngine On +
-  RewriteCond %{REQUEST_METHOD} ^HEAD|GET$ +
-  RewriteRule .* - [E=Cache-Control:max-age=120] +
-  </IfModule><​/code>  +
-   +
-These rules enable cache for everything for two minutesThe ''​RewriteCond''​ for ''​%{REQUEST_METHOD}''​ is optional in general, but if do use it, and you want the ability to purge the cache, you will need to add ''​PURGE''​ to it.  +
- +
-Change the rewrite rules, like so: +
-<​code><​IfModule LiteSpeed>​ +
-  RewriteEngine On +
-  RewriteRule .* - [E=Cache-Control:​max-age=120] +
-  </​IfModule></​code> ​  +
- +
-The cache purge can be initiated through the following curl command: +
-<​code>​curl -i -X PURGE http://​example.com/</code> +
- +
-Please note that if the homepage ''<​nowiki>​http:​//​example.com/​index.php</​nowiki>''​ needs to be purged, the trailling ''/''​ is required. The follwing command won't work: +
-<​code>​curl -i -X PURGE http://​example.com</​code>​ +
- +
-The above curl command can be run either within the server or from a remote server. If a purge curl command is to be run from a remote server, the remote server IP will need to be added to LiteSpeed Web Server'​s Trusted IP list. Navigate to **LSWS Admin Console > Configuration > Server > Security**, and append the source IP with a trailing ''​T''​ to **Allow List**. (The ''​T''​ signifies the IP is Trusted. It should look like ''​ALL,​ x.x.x.xT''​) . +
- +
-===== Testing ===== +
- +
-Visit ''<​nowiki>​http://​example.com/</​nowiki>''​ through the browser and ensure ''​X-Litespeed-Cache:​ hit''​ is set. +
-  +
-Then, using the above curl command, purge the homepage either within the server or from a remote server, like so: +
-<​code>​curl -i -X PURGE http://​example.com/​ +
- +
-HTTP/1.1 200 Purged +
-Content-Length:​ 0 +
-Date: Fri, 28 Jun 2019 18:26:46 GMT +
-Server: LiteSpeed +
-Alt-Svc: quic=":​443";​ ma=2592000; v="​35,​39,​43,​44"​ +
-Connection: close +
-</​code>​ +
- +
-Check the header of ''<​nowiki>​http://​example.com/</​nowiki>''​ again, and it should show ''​X-Litespeed-Cache:​ miss''​ instead of ''​X-Litespeed-Cache:​ hit''​. This means the cache was purged successfully. If you hit the URL the second time, you should see ''​X-Litespeed-Cache:​ hit''​ again.+
  • Admin
  • Last modified: 2020/09/23 20:44
  • by Lisa Clarke