Looking for the approaches to cache content of custom plugins
-
Hi there,
I’m getting my self developed plugins ready for the LiteSpeed Web Server and the LiteSpeed Cache plugin. There must be adjustments done to make the caching work. Since I’m new to the subject, I want to ask for the best approaches.
- The first plugin enables users to have discounts. There’s a database table in which the discounts are stored. I want the users with the same discount value to use the same cache. I see 2 possible solutions:
- Make use of a Cache Vary: Set a cookie for every user in my plugin and add this cookie to the rewrite rules as described here (Is there a way to add this vary in the LSCache plugin settings?). But I’d prefer a cookie-free solution. In the doc environment variables are mentioned. Are they helpful here?
- Make use of ESI’s: I’m not sure if this is the way to go, since prices appear on every page, e.g. because of products in the footer. But theoretically I could wrap all of the price appearances in ESI’s. Also, I’d like to know if it’s possible here to have a cache vary inside an ESI. So if users don’t have a discount, the “standard” ESI content (or even better the full page content) is loaded and if users have a 15% discount, all of them get the same cached ESI content.
- In the second plugin there’s a calculator where visitors/users can individually set parameters for an equation. These parameters are saved as cookies for visitors and as user meta for users. I see 2 possible solutions:
- Create an ESI: Here I’d only like to use the ESI if the specific cookies/meta exist. So for the standard user with no set cookies, the full cached page should be loaded (similar to the ESI approach of the first plugin)
- Load the parameters via AJAX: Just like some plugins/themes do it with the cart. Can you recommend this method and can you tell how it compares to an ESI?
Do you have better approaches?
I’d be happy if you could provide code samples of your approaches.
Thank you!
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Looking for the approaches to cache content of custom plugins’ is closed to new replies.