Why use Litespeed/LSCache with Drupal? Because it is bloody fast, that’s why! Honestly, LSCache is a great bonus for those clients running Drupal on our shared hosting. Even better, it is really simple to get it setup.
Currently, there is no module for Litespeed Cache (we know, there’s a module for that! Well, except this…). However, you can implement caching quite easily by adding the following to the top of your htaccess file:
CacheEnable public
RewriteEngine On
RewriteCond %{REQUEST_METHOD} ^GET|HEAD|PURGE$
RewriteCond %{REQUEST_URI} !admin|register|login [NC]
RewriteCond %{HTTP_COOKIE} !SESS [NC]
RewriteCond %{QUERY_STRING} !nocache
RewriteRule .* – [E=Cache-Control:max-age=300]
If you need to view the non-cached version of any URL, just add &nocache to the end of the URL in your address bar. For example, you could visit www.yourdomain.com/blog/somenewpost&nocache to view the non cached version of www.yourdomain.com/blog/somenewpost
If you have more than one domain in your public_html directory, add the following line before the last two lines:
RewriteCond %{HTTP_HOST} ^yourdomain.com [NC]
To verify cache is working, you can simply examine the raw HTTP headers sent between the browser and web server. We prefer using Chrome Developer Tools to check this. When a page is served from the litespeed cache, the following line shows up in the HTTP response header:
X-LiteSpeed-Cache: hit
If you do not see this in the HTTP response header, then the page was not served from the cache. At that point, feel free to open a support ticket with us for further assistance.
But if you are seeing the cache hit, you’ll notice the tremendous improvement in page load speeds your Drupal site now has.