Differences

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

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Last revision Both sides next revision
litespeed_wiki:cache:developer_guide:cache-vary [2017/02/28 15:30]
Kevin Fwu [Rewrite Rules]
litespeed_wiki:cache:developer_guide:cache-vary [2017/02/28 22:15]
Kevin Fwu [Vary Cookie]
Line 2: Line 2:
  
 The Cache Vary is an important concept for caching. For simplicity'​s sake, the idea behind cache varies is that they allow the cache to save multiple versions of the same URL. The Cache Vary is an important concept for caching. For simplicity'​s sake, the idea behind cache varies is that they allow the cache to save multiple versions of the same URL.
 +
 +Using the public cache key as an example, KEY = Host + URI + Query String + VARY
 +
 +This article describes the VARY portion of the cache key.
  
 ===== Examples of reasons to use cache vary: ===== ===== Examples of reasons to use cache vary: =====
Line 10: Line 14:
  
 There are two types of cache varies, vary cookie and vary value. Both are used when determining which version to return. Setting a Vary Cookie will notify the server about which cookies to keep an eye on. This will not actually set a cookie. Setting a Vary Value will set an environment value strictly for the use of varying the request. There are two types of cache varies, vary cookie and vary value. Both are used when determining which version to return. Setting a Vary Cookie will notify the server about which cookies to keep an eye on. This will not actually set a cookie. Setting a Vary Value will set an environment value strictly for the use of varying the request.
 +
 +Using the earlier cache key equation, VARY can be expanded to:
 +
 +VARY = VARY_COOKIE + VARY_VALUE
  
 ==== Vary Cookie ==== ==== Vary Cookie ====
Line 17: Line 25:
  
   * Request A has NO cookies.   * Request A has NO cookies.
 +    * ''​VARY = ""''​
   * Request B has the cookie my_cookie = Alabama   * Request B has the cookie my_cookie = Alabama
 +    * ''​VARY = "​my_cookie=Alabama"''​
   * Request C has the cookie my_cookie = California   * Request C has the cookie my_cookie = California
 +    * ''​VARY = "​my_cookie=California"''​
   * Request D has the cookie my_cookie = Alabama   * Request D has the cookie my_cookie = Alabama
 +    * ''​VARY = "​my_cookie=Alabama"''​
  
 For this example, Requests B and D will get the same cached version (or another way to see it: request B can generate the cache entry for request D). Their cache entry will differ from requests A and C, both of which have a unique cache entry. So there are 3 total cache entries. For this example, Requests B and D will get the same cached version (or another way to see it: request B can generate the cache entry for request D). Their cache entry will differ from requests A and C, both of which have a unique cache entry. So there are 3 total cache entries.
Line 26: Line 38:
  
 ==== Vary Environment Value ==== ==== Vary Environment Value ====
-The Cache Vary Value is value used to vary request. ​Only one vary value may be used. If multiple environment values are set, only the last one will be used.+The Cache Vary Value is an environment ​value to vary the request. ​The Vary Value differs from Vary Cookies in that the Value set is the value used. There is no key to check and only one vary value may be used. If multiple environment values are set, only the last one will be used
 + 
 +  * Request A has no vary value 
 +    * ''​VARY = ""''​ 
 +  * Request B sets vary value "​ismobile"​ 
 +    * ''​VARY = "​ismobile"''​ 
 +  * Request C sets vary value "​US"​ 
 +    * ''​VARY = "​US"''​ 
 +  * Request D sets vary value "​US"​ 
 +    * ''​VARY = "​US"''​ 
 + 
 +For this example, Requests C and D will get the same cached version (or another way to see it: request C can generate the cache entry for request D). Their cache entry will differ from requests A and B, both of which have a unique cache entry. So there are 3 total cache entries.
  
 An example use case is the separate mobile view use case listed above. Given the request'​s user agent, if it matches a mobile browser, one can set vary value = '​ismobile'​. This will be covered in the next section below. An example use case is the separate mobile view use case listed above. Given the request'​s user agent, if it matches a mobile browser, one can set vary value = '​ismobile'​. This will be covered in the next section below.
 +
 +===== =====
 +
 +Vary Cookies and Vary Values can both be set. Setting one does not limit setting another. ​
 +
 +Suppose the server is instructed to vary on the cookies '​my_cookie'​ and '​my_cookie2'​.
 +
 +  * Request A has no cookies and no vary value is set.
 +    * ''​VARY = ""''​
 +  * Request B has the cookie '​my_cookie=Alabama'​ and no vary value is set.
 +    * ''​VARY = "​my_cookie=Alabama"''​
 +  * Request C has the cookie '​my_cookie=Alabama'​ and vary value '​ismobile'​ is set.
 +    * ''​VARY = "​my_cookie=Alabama"​ + "​ismobile"''​
 +  * Request D has the cookies '​my_cookie=Alabama'​ and '​my_cookie2=Apple'​ and vary value '​ismobile'​ is set.
 +    * ''​VARY = "​my_cookie=Alabama&​my_cookie2=Apple"​ + "​ismobile"''​
 +  * Request E has no cookies, but vary value '​ismobile'​ is set.
 +    * ''​VARY = "​ismobile"''​
 +
 +The five requests will all be served a different cache entry, because their final VARY results are different.
  
 ===== How to instruct the server to use a custom vary ===== ===== How to instruct the server to use a custom vary =====
Line 45: Line 87:
 This example rewrite rule will instruct the server to check for the "​my_cookie"​ cookie NAME and if it exists, vary on it. This example rewrite rule will instruct the server to check for the "​my_cookie"​ cookie NAME and if it exists, vary on it.
  
-As of LSWS version 5.1.x and OLS 1.4.x, it is possible to add more vary cookies to the rewrite rule. +As of LSWS version 5.1.x and OLS 1.4.x, it is possible to add multiple ​vary cookies to the rewrite rule. 
  
 Example: Example:
Line 75: Line 117:
 Example header: Example header:
  
-X-LiteSpeed-Vary:​ cookie=my_cookie,​cookie=my_cookie2+''​X-LiteSpeed-Vary:​ cookie=my_cookie,​cookie=my_cookie2''​
  
 This response header will add two vary cookies, '​my_cookie'​ and '​my_cookie2',​ to the list of varies to check for this URL. On the next request for this URL, the server will check for the vary cookies set by the rewrite rules //in addition to// the two cookies above as if they were part of the rewrite rule. This response header will add two vary cookies, '​my_cookie'​ and '​my_cookie2',​ to the list of varies to check for this URL. On the next request for this URL, the server will check for the vary cookies set by the rewrite rules //in addition to// the two cookies above as if they were part of the rewrite rule.
  • Admin
  • Last modified: 2020/07/31 19:35
  • by Lisa Clarke