Response Headers

The following response headers are geared specifically for use with LiteSpeed Cache. If the server is not a LiteSpeed server or if the cache module is not registered, these headers will be ignored.

The spaces between tags are optional. Better removed for performance.

Functions similarly to the regular “Cache-control” header, but is for internal use. LiteSpeed Web Server will follow this if it is set, regardless of the value of the “Cache-control” header. Possible values are:

  • “no-cache”
  • “no-store”
  • “max-age”
  • “max-stale”
  • “public”
  • “private”
  • “s-maxage”
  • “no-vary”
  • “esi”

Use the following header to turn on ESI for a specific response:
X-LiteSpeed-Cache-Control: esi=on

To cache a response for an hour:
X-LiteSpeed-Cache-Control: public, max-age=3600

Format examples:
X-LiteSpeed-Cache-Control: private, max-age=864020
X-LiteSpeed-Cache-Control: shared, private, no-vary, max-age=864020, esi=on

Tell LiteSpeed Web Server to purge cache objects, it can purge by URL, or by Tag.

For purge header, “public” is optional for purge, “private” is required.
For purge header, “tag=” is optional too.

Purge all public cache:
X-LiteSpeed-Purge: *

Purge all private cache for the current user:
X-LiteSpeed-Purge: private, *

Purge public cache by Tag:
X-LiteSpeed-Purge: tag=Cat1, tag=Page2

Purge private cache by Tag:
X-LiteSpeed-Purge: private, tag=Cat1, tag=Page2

Purge by URL: Currently, only URLs that exactly match are supported
X-LiteSpeed-Purge: /phpinfo.php
X-LiteSpeed-Purge: private, /phpinfo.php

As of now, this does not support regular expressions or wildcards in the Tag and URL, these will be added later.

Format examples:
X-LiteSpeed-Purge: public, tag=pubtag1, tag=pubtag2; private, tag=privtag1, tag=privtag2
X-LiteSpeed-Purge: public, tag=pubtag1, tag=pubtag2; private, tag=*
X-LiteSpeed-Purge: public, stale, tag=pubtag1, tag=pubtag2; private, stale, tag=privtag1, tag=privtag2
X-LiteSpeed-Purge: pubtag1, pubtag2, pubtag3; private, *
X-LiteSpeed-Purge: pubtag1, pubtag2, pubtag3; private, privtag1, privtag2
X-LiteSpeed-Purge: stale, pubtag1, pubtag2, pubtag3; private, stale, privtag1, privtag2
X-LiteSpeed-Purge: pubtag1, pubtag2~s, pubtag3; private, privtag1, privtag2 (Only pubtag2 is stale)

For cache tags, if cache control is public, “public:” prefix is optional if the tag is public.
For cache tags, if cache control is private, “public:” prefix is required if the tag is public.

Assign a tag to a cache object. Each object can have multiple tags assigned to it.
X-LiteSpeed-Tag: Cat1, Page3

Tags are saved together with the cache object.

The main purpose of tagging is to purge cache objects by tag.

More examples:
X-LiteSpeed-Tag: public:pubtag1, public:pubtag2
X-LiteSpeed-Tag: pubtag1, pubtag2

If has X-LiteSpeed-Cache-Control: private, max-age=3600 then
X-LiteSpeed-Tag: public:pubtag1, public:pubtag2, public:pubtag3, privtag1, privtag2

NOTE: Since they are going to be used in a response header, tags must follow response-header rules. As such only ASCII characters are allowed, and no special characters (spaces, commas, quotes) may be used. Additionally, the public: prefix is reserved.

Set the cache vary for the current response:

X-LiteSpeed-Vary: value=US

This tells the server to cache the object with a vary value of “US”. This will not affect the varies used by other pages.

The response header vary value cannot be used by itself. The cached object cannot be reached as the vary value will never be set when the request comes in (only when the response goes out). To retrieve it for a request, you can use the following rewrite rule:

RewriteRule /us/view - [E=cache-control:vary=US]

To register a list of vary cookies for the current response:

X-LiteSpeed-Vary: cookie=cookie1,cookie=cookie2

The server needs to track vary cookies for each individual URL saved in cache manager storage. This is expensive and should be avoided whenever possible.

The rewrite rule method is preferred as it does not need to save for every URL.

Generally speaking, cookies will contain private information, so by default, all pages that are cached in LiteSpeed Cache will have the ‘Set-Cookie’ header dropped. The lsc-cookie header is used to send out a ‘Set-Cookie’ header for the pages served from cache. The lsc-cookie header follows the same syntax as a Set-Cookie header, but will be sent to the client along with the cached page.

In other words, the lsc-cookie is a cacheable Set-Cookie which will be converted and sent out as a Set-Cookie.

For example, suppose I have <?php header(‘LSC-Cookie: lsc_cached_page=1’); ?> in my plugin. When the page is served from cache, the response header will include Set-Cookie: lsc_cached_page=1.

One example of how to use this is to check if the client supports cookies. If the web application always generates a cookie on every page and a page is served from the cache without any cookies, the web application may assume that the client does not have cookies enabled.

This header is inserted by Litespeed Web Server when it serves from cache, possible values are:
X-LiteSpeed-Cache: hit
X-LiteSpeed-Cache: hit,private
X-LiteSpeed-Cache: hit,litemage

  • Admin
  • Last modified: 2018/11/21 17:23
  • by Lisa Clarke