• Resolved advian

    (@advian)


    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:
    1. 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?
    2. 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:
    1. 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)
    2. 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!

    • This topic was modified 4 years, 4 months ago by advian.
    • This topic was modified 4 years, 4 months ago by advian.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Hai Zheng?

    (@hailite)

    Hi,

    The possible solutions you mentioned are exactly what I think. Either case, I don’t think you need ESI. Bcos even you used ESI, you still need to set a vary to maintain separate content cache copies. Besides, ESI section will be an additional request to your server. Whole page cache w/ vary could be easier. Vary in rewrite rule is the easiest way to achieve it.

    For your 2nd plugin, as the parameters are different for each visitor, it will be better to load via AJAX. BTW, if your cookie format set by PHP can be read by JS, that can save the AJAX PHP hit to server side. (For guests, just load the data in AJAX from cookie).

    Best regards

    Thread Starter advian

    (@advian)

    Is there a way to use varies without setting cookies? Could you explain a scenario where environment variables would be helpful?

    And can I set the rewrite rule within the plugin? If not, it would be a nice feature to integrate I think ??

    Thanks for the tip with creating dynamic content by settings cookies and processing them with JS!

    Plugin Support qtwrk

    (@qtwrk)

    Hi,

    Technically , yes, you can use something like server env , but server env is more like “one-time” vary and vary might be changed in short time , where cookie can be used for longer period

    May I know what rule you want to add ? for most cases ,the rule should be working even you place it outside of plugin’s block

    Best regards,

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.