Configure Server Level Cache

How Can We Help?
< Back
You are here:
Print

OpenLiteSpeed offers built-in page caching to greatly improve page load times. You can find the server-level settings in the WebAdmin Console under Server Configuration > Modules > Cache or in the configuration file located at /usr/local/lsws/conf/httpd_config.conf.

Cache Settings Explained

The OpenLiteSpeed cache module parameters mirror the cache settings in Enterprise. These parameters provide basic ways of setting up the cache.

  • enableCache = This setting enables or disables public cache. (Set to 1 to enable. Set to 0 to disable.) If both public and private cache are enabled, OpenLiteSpeed will save to the private cache first.
  • qsCache = This setting enables or disables caching of URIs with query strings. (Set to 1 to enable. Set to 0 to disable.)
  • reqCookieCache = This setting tells the cache how to react to requests with cookies. If enabled (set to 1), requests with cookies will be served a response from cache if a cached copy exists. If disabled (set to 0), requests with cookies, will not be served a response from cache (even if a cached copy of the response exists).
  • respCookieCache = This setting tells the cache how to treat responses with a Set-Cookie header. If enabled (set to 1), responses with a Set-Cookie header will be cached. If disabled (set to 0), responses with a Set-Cookie header will not be cached.
  • ignoreReqCacheCtrl = Enabling this setting (set to 1) will tell LiteSpeed’s cache to ignore any cache control settings in the request.
  • ignoreRespCacheCtrl = Enabling this setting (set to 1) will tell LiteSpeed’s cache to ignore any cache control settings in the response.
  • expireInSeconds = This setting sets the expiration time (in seconds) for cached resources.
  • maxStaleAge = This setting sets the maximum time (in seconds) that the cache can serve stale cache. (Stale cache refers to the serving of expired cached resources when a newer resource is not yet available.)
  • enablePrivateCache = This setting enables or disables private cache. (Set to 1 to enable. Set to 0 to disable.) If both public and private cache are enabled, OpenLiteSpeed will save to the private cache first.
  • privateExpireInSeconds = This setting sets the expiration time (in seconds) for cached resources in a private cache.
  • storagePath = This setting sets the directory where cache data will be stored. Paths starting with a / will use an absolute path. Paths without the starting / will be relative to the OpenLiteSpeed root directory. The variables $VH_ROOT, $VH_NAME and $SERVER_ROOT can be used to designate separate caches for different virtual hosts. If this parameter is not explicitly configured, cache will be stored in a cachedata directory under the OpenLiteSpeed root. For example, storagepath cachedataor storagepath /usr/local/lsws/cachedataor storagepath $SERVER_ROOT/cachedata
  • checkPrivateCache = Enabling this setting (set to 1) will tell LiteSpeed’s cache to check the private cache for entries to serve from the cache.
  • checkPublicCache = Enabling this setting (set to 1) will tell LiteSpeed’s cache to check the public cache for entries to serve from the cache.

NOTE: The enableCache and enablePrivateCache settings are not available at the server level, as it is strongly recommended that you not enable caching server-wide. If you have a need for global caching, you may configure a Context for that purpose.

You can change settings from the WebAdmin Console interface, or you can vi /usr/local/lsws/conf/httpd_config.conf to edit the config file.

This is a sample configuration that you can copy and paste into the config file:


module cache {
  internal                1
  ls_enabled              1

storagePath $SERVER_ROOT/cachedata
checkPrivateCache   1
checkPublicCache    1
maxCacheObjSize     10000000
maxStaleAge         0
qsCache             1
reqCookieCache      1
respCookieCache     1
ignoreReqCacheCtrl  1
ignoreRespCacheCtrl 0

enableCache         0
expireInSeconds     3600
enablePrivateCache  0
privateExpireInSeconds 3600
  
}

 

 

Cache Settings Inheritance

All modules must be registered at the server level. Once a module is registered, it’s settings are inherited by more specific setting levels (virtual host, context, and script handler). Configurations can be modified at these more specific levels. Settings at more specific levels always override more general levels. For example, virtual host-level configurations override server-level configurations and context-level configurations override virtual host-level configurations.

Set up Virtual Host-Level Cache Settings

If you run a shared hosting server, you may wish to set up vhost-level settings for each individual user’s root. If no vhost-level configuration is set, the server-level configuration will be inherited.

To set up vhost-level caching, add the cache module under each virtual host, and edit the settings there in the same way that you did at the server level.

For example, go to Example Virtual Host > Modules > Add, and select cache from the module drop down list. Enter Module Parameters for cache settings, and set Enable Module to Yes.

You can change any setting that you wish, but the most important virtual host cache setting should be storagePath $VH_ROOT/lscache, which will set the path to be different than the server level. Each user will have the ability to purge cache from their own account.

This is a sample configuration that you may copy and paste:


module cache {
  ls_enabled              1

storagePath $VH_ROOT/lscache
checkPrivateCache   1
checkPublicCache    1
maxCacheObjSize     10000000
maxStaleAge         0
qsCache             1
reqCookieCache      1
respCookieCache     1
ignoreReqCacheCtrl  1
ignoreRespCacheCtrl 0

enableCache         0
expireInSeconds     3600
enablePrivateCache  0
privateExpireInSeconds 3600
  
}

Using LSCache

Configuring the cache module at the server level is only one part of the equation. You still need to enable caching for your web apps, and this can be done by installing the corresponding LSCache plugin, or using rewrite rules in .htaccess if no plugin is available.

Test

You can tell that LSCache is working by looking at the headers on cacheable pages. A page served from public cache will display the header X-LiteSpeed-Cache: hit. A page served from private cache will display the header X-LiteSpeed-Cache: hit, private.