Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter Georgi Tsvetanov

    (@gtsvetanov)

    Hello,

    As I said in my first topic Add Cache key generation hook – I’ve already made the changes if you wish to add it in your plugin the pleasure will be mine!

    Once again – Thank you for your amazing work because this plugin saved me a lot of time.

    Best regards,
    Georgi!

    Plugin Author Richard Korthuis

    (@rockfire)

    Hi @gtsvetanov

    I’m trying to understand your issue. Am I correct that you want to invalidate caches by using a url? If so we have a function for that which you can use (and it will take all of your example url’s to flush the correct cache), for instance:

    \WP_Rest_Cache_Plugin\Includes\Caching\Caching::get_instance()->delete_cache_by_endpoint( '/wp-json/wp/v2/endpoint?original=1&a=2' );

    Thread Starter Georgi Tsvetanov

    (@gtsvetanov)

    Hello @rockfire

    This won’t help because the method you gave me makes a little manipulation of the url as build_request_uri() method in class Endpoint_Api do. I don’t know what is your knowledge about Cloudflare CDN (used in my project) but in their lower plans (except Enterprise) these URLs are completely different for them:

    
    - https://example.com/wp-json/wp/v2/endpoint?original=1&a=2
    - https://example.com/wp-json/wp/v2/endpoint/?original=1&a=2
    - https://example.com/wp-json/wp/v2/endpoint?a=2&original=1
    - https://example.com/wp-json/wp/v2/endpoint/?a=2&original=1
    

    But for the plugin these URLs will generate the same key as I said. Because of few points:
    $request_path = rtrim( $uri_parts['path'], '/' ); ~ line 229 – will remove right “/”
    ksort( $params ); ~ line 233 – this will sort params in the query string.

    If you check build_request_uri method the plugin doing the same. Also if you don’t want to add this change then please add it to the documentation because this behavior was unexpected for me ??

    Plugin Author Richard Korthuis

    (@rockfire)

    Hi @gtsvetanov

    I am still not sure what the issue is? So Cloudflare CDN treats the urls as different “pages”, but why should our plugin treat them differently when in fact these url’s are all the same “page”? Without our plugin WordPress also treats these url’s all the same way.
    In my opinion it is Cloudflare who is acting strange, since technically there isn’t anything different for these url’s they all contain exactly the same content, so they should all be treated the same way. If content for url 1 is invalidated for some reason, then the content for url’s 2 to 4 should also be invalidated. Which is exactly what our plugin does.
    We deliberately build it this way in order to avoid unnecessary caches. Why have 4 caches when in fact they are all the same?

    Thread Starter Georgi Tsvetanov

    (@gtsvetanov)

    Hello @rockfire

    Think about this: We have a public accessed API and there is no way to control how customer calls any endpoint in it. They can add parameters in random ordering and that’s fine for me, for the plugin and for cloudflare.

    When there is an update to post related with the cache the plugin properly invalidates the cache and that’s fine too but I have to invalidate the cache on Cloudflare too. To prevent calling “purge all” I have to clear the cache by URLs but URLs are different – by their query params ordering and with/out “/” at the end and Cloudflare treats them as completely different because they are.

    How different they are (I love to compare everything with hashes):

    
    - https://example.com/wp-json/wp/v2/endpoint?original=1&a=2 - 91e82a98319b29979c19dae86129a0f9cdc51ef7
    - https://example.com/wp-json/wp/v2/endpoint/?original=1&a=2 - 642946ef5797e6d239fa5e595e6d13c6b6a66d06
    - https://example.com/wp-json/wp/v2/endpoint?a=2&original=1 - 015bb748f63d78d9f73d7bd25e3ff84f996f0798
    - https://example.com/wp-json/wp/v2/endpoint/?a=2&original=1 - 21548134109a41ebdca3b2f238c9e1ba9d4c7846
    

    I understand why the plugin makes all of these manipulations – to decrease amount of cached keys and to combine same resources no matter of used URL. This will cause higher cache hit rate. On the other hand I have to call CF to purge caches for these resources but the plugin recorded only the manipulated URL so I know for only one URL but people can access the same resource on different URLs ?? That’s all ??

    For me the issue is not in the Plugin but plugin can help with the solving of it.

    Plugin Author Richard Korthuis

    (@rockfire)

    Hi @gtsvetanov

    Thanks for the explanation. I didn’t realize you have to invalidate the Cloudflare caches from within WordPress, then it makes sense you need all posible url’s. However, I don’t like the idea of our plugin storing all url’s for a single cache by default, since this isn’t something the majority of our users will be needing and it is storing extra information in the database.
    My initial thought was to fire a hook once the cache key is generated with the cache key and the original url. But here we are running into the issue that it is executed from a must use plugin and therefore no other code is executed if there is an active cache. So that is not an option.
    Another option would be to make it a setting where you can choose if all url’s for a single cache should be saved or not. That way we don’t store it if it is not needed, but it would still be available for cases like yours.

    Ofcourse then still we would have to fire a hook every time a cache is invalidated, so you can hook into it to invalidate the Cloudflare caches.

    I am going to put this on our todo-list ??

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Save accessed URLs for a cache key’ is closed to new replies.