Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Emre Vona

    (@emrevona)

    I have read but I could now understand ?? Why do the developers need such feature?

    Thread Starter Diego

    (@daigo75)

    Quite simply, because serving one content to all visitors is often a bad idea.

    A typical example of this are ecommerce sites, where each visitor could need to see different content depending on his location. For example, consider a URL called https://example.org/some-product. Here’s what different visitors should see.

    – Visitor 1, from UK: “price £120 (20% VAT included)
    – Visitor 2, from Germany: “price €119 (19% VAT included
    – Visitor 3, from the US: “price $150
    – Visitor 4, from Canada: “price CA$200

    The URL is exactly the same in call cases (there are no URL arguments), but the content is different. In short, the assumption that “one URL = one content” is incorrect, and should not be relied upon.

    When a caching system is restricted to serving the same content to everybody, the only solution is to disable it on the dynamic pages, thus defeating the purpose of having one.

    The solution
    By allowing a dynamic cache key (which can be done with a filter), a caching system can create multiple copies of content for each URL. From the example above, instead of having one content for the four visitors, you could have:
    – Visitor 1 -> Cache key = https://example.org/some-product + “UK” -> Content for UK visitors
    – Visitor 2 -> Cache key = https://example.org/some-product + “DE” -> Content from German visitors
    – Visitor 3 -> Cache key = https://example.org/some-product + “US” -> Content for US visitors
    – Visitor 4 -> Cache key = https://example.org/some-product + “CA” -> Content for Canadian visitors

    Such kind of flexibility is not just “nice to have”, but critically important for websites aimed at an international audience, where the content could vary greatly. There are caching solutions (plugins and servers) that already provide this feature, while others are being updated for that (e.g. WP Rocket, WordFence Falcon), hence my enquiry about WP Fastest Cache. ??

    Plugin Author Emre Vona

    (@emrevona)

    hmm. I will think about it.

    Thread Starter Diego

    (@daigo75)

    Sure, mine was a suggestion. Implementing a module system should be easy enough, it’s a matter of loading some files from a specific folder (see ZenCache codebase for an example, method advanced_cache::load_ac_plugins().

    You can then add a filter to which modules can hook, and let them set the cache key before you use it as the index for your cached files.

    I haven’t looked at your plugin code, but the logic itself is quite straightforward. ??

    Plugin Author Emre Vona

    (@emrevona)

    Just I cannot imagine something. If WPFC is enable, php and mysql do not work. User is redirected to the static html file. How can I catch the parameters?

    Thread Starter Diego

    (@daigo75)

    That’s incorrect. If WPFC works like other caching plugins, WordPress is loaded to a certain extent, and you can invoke filters. When you generate your cache key, you will simply call:

    $cache_key = apply_filters('your_cache_key_filter', $cache_key);

    This will give modules the opportunity to alter the key as they wish.

    The actual implementation of such mechanism depends entirely on your plugin’s architecture, there isn’t a “specific and global way” to do it. ??

    Plugin Author Emre Vona

    (@emrevona)

    Diego, please let me explain how WPFC works.

    for First User;

    User –> Apache –> PHP+MySQL –> output

    for Next Users;

    User –> Apache –> output

    The goal of WPFC is the best performance. For best performance we need to stop using mysql and php. Did you get it?

    Thread Starter Diego

    (@daigo75)

    I’m still not sure how a WordPress plugin could work without loading WordPress at all, but, if you only pass through Apache, then it might be possible to use some sort of custom rule, like Nginx does. Here’s an example rule that produces a dynamic cache key using the cookies produced by our plugins:

    # Add Aelia cookies to the cache key. This will create multiple copies of each
    # cached page (one for each combination of currency, country and province/state)
    proxy_cache_key "$scheme$request_method$host$request_uri $cookie_aelia_cs_selected_currency$cookie_aelia_customer_country$cookie_aelia_customer_state$cookie_aelia_billing_country";

    I’m not sure if that is possible with your architecture, but that would be the idea.

    Plugin Author Emre Vona

    (@emrevona)

    thank you so much.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Feature suggestion – Dynamic cache key’ is closed to new replies.