Skip to content

LiteSpeed Cache

LiteSpeed Cache (LSCache) is a server-level full-page cache built into OLS. It stores rendered HTML pages and serves them directly from the web server, bypassing PHP entirely for cached requests. This can improve response times by 10-100x for cacheable pages.

In httpd_config.conf:

module cache {
ls_enabled 1
checkPublicCache 1
checkPrivateCache 1
maxCacheObjSize 10000000
maxStaleAge 200
qsCache 1
reqCookieCache 1
respCookieCache 1
ignoreReqCacheCtrl 1
ignoreRespCacheCtrl 0
storagePath /usr/local/lsws/cachedata
enableCache 0
enablePrivateCache 0
}
ParameterDefaultDescription
ls_enabled1Load the cache module
checkPublicCache1Check for publicly cached pages
checkPrivateCache1Check for privately cached pages (per-user)
maxCacheObjSize10000000Maximum size of a cached object in bytes (~10 MB)
maxStaleAge200Seconds a stale cache entry can be served while revalidating
qsCache1Cache pages with query strings
reqCookieCache1Allow caching when request has cookies
respCookieCache1Allow caching when response sets cookies
ignoreReqCacheCtrl1Ignore client Cache-Control headers
storagePath/usr/local/lsws/cachedataDirectory for cached files
enableCache0Enable public cache at server level (application must still send cache headers)
enablePrivateCache0Enable private cache at server level

Enable caching for a specific virtual host:

virtualhost example {
...
module cache {
enableCache 1
enablePrivateCache 1
storagePath /usr/local/lsws/cachedata/example
}
}

LSCache uses response headers from the application to determine caching behavior:

HeaderDescription
X-LiteSpeed-Cache-Control: public, max-age=3600Cache publicly for 1 hour
X-LiteSpeed-Cache-Control: private, max-age=1800Cache per-user for 30 minutes
X-LiteSpeed-Cache-Control: no-cacheDo not cache this response
X-LiteSpeed-Tag: tag1, tag2Assign cache tags for selective purging
X-LiteSpeed-Purge: tag1Purge all entries with this tag
X-LiteSpeed-Purge: *Purge all cached entries

These headers are consumed by OLS and not sent to the client.

The LiteSpeed Cache plugin for WordPress is the most popular LSCache integration. It automatically sends the appropriate cache headers.

Terminal window
wp plugin install litespeed-cache --activate --allow-root

In LiteSpeed Cache > General:

  • Enable LiteSpeed Cache: On
  • Guest Mode: On

In LiteSpeed Cache > Cache:

  • Cache Logged-in Users: Off
  • Cache Mobile: On (for responsive themes)
  • Default Public Cache TTL: 604800 (7 days)
  • Default Private Cache TTL: 1800 (30 min)

In LiteSpeed Cache > Cache > Purge:

  • Purge All On Upgrade: On

The WordPress plugin automatically tags cached pages:

  • Posts: P.{post_id}
  • Categories: T.{term_id}
  • Authors: A.{author_id}
  • Front page: FP
  • 404 pages: 404

When a post is updated, only pages tagged with that post’s ID are purged.

For custom applications, send cache headers from your application:

// Cache publicly for 1 hour
header('X-LiteSpeed-Cache-Control: public, max-age=3600');
header('X-LiteSpeed-Tag: page, page_' . $page_id);
// Dynamic pages - no cache
header('X-LiteSpeed-Cache-Control: no-cache');
class LiteSpeedCache
{
public function handle($request, Closure $next)
{
$response = $next($request);
if ($request->isMethod('GET') && !auth()->check()) {
$response->header('X-LiteSpeed-Cache-Control', 'public, max-age=3600');
}
return $response;
}
}

Send a purge header from your application:

header('X-LiteSpeed-Purge: *'); // Purge everything
header('X-LiteSpeed-Purge: tag1, tag2'); // Purge specific tags
Terminal window
# Purge all cached files
rm -rf /usr/local/lsws/cachedata/*
# Restart to clear in-memory cache index
systemctl restart lsws
Terminal window
# WP-CLI
wp litespeed-purge all --allow-root
# Or from the WordPress admin bar: LiteSpeed Cache > Purge All

Monitor cache disk usage:

Terminal window
du -sh /usr/local/lsws/cachedata/

For maximum cache performance, mount the cache storage on a tmpfs:

Terminal window
mount -t tmpfs -o size=1G tmpfs /usr/local/lsws/cachedata

Add to /etc/fstab for persistence across reboots:

tmpfs /usr/local/lsws/cachedata tmpfs size=1G,noatime 0 0

Check the response headers to verify caching:

Terminal window
curl -I https://example.com

Look for:

X-LiteSpeed-Cache: hit # Served from cache
X-LiteSpeed-Cache: miss # Not in cache, response was generated
X-LiteSpeed-Cache: hit,private # Served from private cache

Cache always shows “miss”:

  • Verify enableCache is 1 for the virtual host
  • Check that the application sends X-LiteSpeed-Cache-Control headers
  • Ensure the response does not have Set-Cookie headers (unless respCookieCache is enabled)
  • Check that the URL does not match any no-cache rules

Stale content after updates:

  • Verify purge mechanism is working
  • Check cache TTL values
  • For WordPress, ensure the LiteSpeed Cache plugin purge hooks are active

Cache not working for logged-in users:

  • This is by default — logged-in users get dynamic responses
  • Enable private cache if needed: X-LiteSpeed-Cache-Control: private, max-age=1800