Starting in LiteSpeed Web Server 5.0, LiteSpeed is adding ESI support. Using ESI to increase cache usage allows you to supercharge web applications like Magento or WordPress.
What Is ESI?
ESI stands for Edge Side Includes. It is a markup language that allows you to designate parts of your dynamic page as separate fragments that are then assembled together to make the whole page.
What Can ESI Do?
By designating parts of your page as separate fragments, you can cache (or not cache) different parts of a page in different ways. This allows you to increase your number of cache hits by tailoring your caching to parts of pages instead of having to always reduce caching to the lowest common denominator on that page. You no longer have to designate a whole page as non-cacheable just because one part is non-cacheable.
As an example, traditionally, Magento stores are almost unusable with cache: The shopping cart and other parts of the site are non-cacheable. The shopping cart appears on every page, so, as soon as someone adds something to their cart, every page is non-cacheable. Considering that 90% of your page is still cacheable, it’s awful that you can’t get that benefit just because you have one non-cacheable part. With ESI, you can configure different parts of the page to be treated differently by LSCache. (This is especially easy if you are using the combination of LSCache + Turpentine + Magento. Turpentine is a Magento extension that automatically sets up ESI configuration with the cache.) This means LSCache will be able to serve the parts of the page that can be cached while ignoring the parts that should not be, greatly increasing the speed at which Magento pages can be served. What’s more, LSCache can cache certain parts of the page longer than others, allowing for greater cache use for fragments that are not frequently updated.
How Much of ESI Does LSWS Support? All of It.
All of ESI included in the ESI Language Specification 1.0 is supported. (This is more than some other caching solutions can say…)
How to Enable ESI Support
ESI is enabled with a simple rewrite rule:
RewriteRule .? - [E=esi_on:1]
The above rewrite rule in your server-level configurations would activate ESI support for all pages. If you only have ESI on a specific page, you might want to only enable ESI for that page:
RewriteRule /?my_esi_page.php - [E=esi_on:1]
LSCache + Turpentine + Magento
As mentioned above, one of the easiest ways to implement LSCache’s ESI support is through Turpentine, a Magento extension developed by Nexcess. Turpentine automatically configures Magento and the cache to use ESI in a way that will make use of partial caching and allow for more cache hits. Put the following rewrite rules in an .htaccess file in the root directory of the Magento store to integrate LSCache with Turpentine:
#Turn on ESI for Turpentine and turn on page caching with an expire time of 3600 seconds. RewriteRule .? – [E=esi_on:turpentine,E=cache-control:max-age=3600] #Change the expire time of public cache blocks according to the value in the Turpentine URL. RewriteRule /turpentine/.*/access/public/ttl/(.*)/hmac/ – [E=cache-control:max-age=$1] #Change the expire time of private cache blocks according to the value in the Turpentine URL. RewriteRule /turpentine/.*/access/private/ttl/(.*)/hmac/ – [E=cache-control:private,E=cache-control:max-age=$1] #If you do not want to use private cache, comment out the above rule and uncomment out the rule below. #RewriteRule /turpentine/.*/access/private/ – [E=cache-control:no-cache] #Set the shopping cart to use private cache with an expire time of 300 seconds. RewriteRule /checkout/ – [E=cache-control:private,E=cache-control:max-age=300] #Flush the private cache whenever cart content has been modified. RewriteRule /checkout/cart/(add|delete)/ – [E=cache-control:flush] #If you do not want to use caching for the shopping cart, comment out the above 2 rules and uncomment out the rule below. RewriteRule /checkout/ – [E=cache-control:no-cache] #If caching cause trouble for a URL, just blacklist it using the rule below. #RewriteRule /customer/ - [E=cache-control:no-cache] #Or use private cache for URLs that are having trouble. #RewriteRule /customer/ - [E=cache-control:private]
Note: We are in communication with Nexcess and hope to get more complete support of LSCache with Turpentine.