# LScache

LScache uses so called “Cache Vary”. That means each URL can be cached with different cache copies depending on user related facts like cookie, device and many others. The problem is that Weglot uses PHP and detects language using PHP, but if a page is cached there is no more PHP interpretor, because a cached URL is pure plain text and plain text can’t execute PHP. To make Weglot work with LScache a cookie must be set with different cookie value depending on the selected language. Then this cookie can be used for cache vary so each language gets its own cached copy.

To make it works you can modifiy your Litespeed Vhost with this code :

```php
<IfModule LiteSpeed>
RewriteEngine onCacheLookup on
## Create a separate cache for each language [create a rule for each language you have on your website except the fallback language. In this example we have: FR (original language) + ES (target language) + EN (target but fallback language)] ##
## FR cache ##
RewriteCond %{HTTP:Accept-Language} ^fr [NC]RewriteRule .* - [E=Cache-Control:vary=%{ENV:LSCACHE_VARY_VALUE}+french]
## ES cache ##
RewriteCond %{HTTP:Accept-Language} ^es [NC]RewriteRule .* - [E=Cache-Control:vary=%{ENV:LSCACHE_VARY_VALUE}+spain]
## Create a separate cache if the browser is different from the website - add it imperatively or it will cause issue if the cache is made with the wrong language ##
RewriteCond %{HTTP_COOKIE} ^.*WG_CHOOSE_ORIGINAL.*$RewriteRule .* - [E=Cache-Control:vary=%{ENV:LSCACHE_VARY_VALUE}+wg_choose_original]
</IfModule>
```

Be careful, in some cases, if the Litespeed server is a “fake”, configured with reverse proxies by the host, this code must be added to the Litespeed Vhost. Unfortunately, some hosts do not allow this...


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://developers.weglot.com/wordpress/use-cases/lscache.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
