• Resolved thartl

    (@hartl)


    I need to exclude logged-out administrators from caching.
    Towards that I am setting a cookie when admins log in (admin_device) which persists after they log out.
    This cookie has been added to “Bypass cache for the following cookies” under Cloudflare Workers.
    After I purge cache this is working as expected. But after regular users prime the cache eventually this stops working and users with the “admin_device” cookie start getting cached html.
    At that time I see these header:
    x-wp-cf-super-cache-cookies-bypass: admin_device
    x-wp-cf-super-cache-worker-status: hit
    cf-cache-status: HIT
    When I check the cookie is present and not expired.
    Any ideas what I might be missing?

    The page I need help with: [log in to see the link]

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Contributor iSaumya

    (@isaumya)

    Hi,
    when the user logs out and goes to a different page, can you check the Request Headers > cookies section and if that cookie name is present there or not?

    Cause the worker is basically checking that the cookie name you have mentioned is present in the Request Headers > Cookies list and if so then bypass.

    Thread Starter thartl

    (@hartl)

    Hi Saumya,
    thank you for your reply.
    Yes, the cookie is present in the request header.
    I can also confirm that as long as the cache is not primed for a specific page request the cookie exclusion works. I get:
    x-wp-cf-super-cache-worker-bypass-reason: User provided excluded cookies present in request
    But as soon as I visit the same page in a private window to prime it the cookie exlusion stops working.

    Plugin Contributor iSaumya

    (@isaumya)

    But as soon as I visit the same page in a private window to prime it the cookie exlusion stops working.

    – Cause in the private window that cookie is not present/set. If the cookie is present/set and also present in the request header then the worker will definitely bypass the page.

    Thread Starter thartl

    (@hartl)

    Sorry if I was not clear. If I visit the same page in a private window, then the original window (the one that is still including the cookie in the request) stops being excluded.
    It is still listing the exlusion:
    x-wp-cf-super-cache-cookies-bypass: admin_device
    but results in a hit:
    x-wp-cf-super-cache-worker-status: hit
    and I can still see the cookie in the request.

    Basically, as long as the html is not in the cache I get the response:
    x-wp-cf-super-cache-worker-bypass-reason: User provided excluded cookies present in request
    but as soon as I or someone else requests the page as a normal user then I also start getting a hit despite of the cookie.

    I don’t know, this is confusing to describe, does any of this make sense to you?

    Plugin Contributor iSaumya

    (@isaumya)

    Huh! But that should not be happening. In your Request header if you got the cookie present then it should always bypass whether it’s cached or not. Can you send me a screenshot of the response and request header of when the page is supposed to be bypassed from cache but it’s not?

    Moreover you can also try using the all new Cache Rule inside the Cloudflare dashboard to add an exclusion for your cookie and see how that works.

    Thread Starter thartl

    (@hartl)

    I have added the Cache Rule: https://i.imgur.com/ZxdoYW9.jpg

    Still, pages get exluded at first:

    View post on imgur.com

    View post on imgur.com

    Then after regular users have requested the same page and I try again I get:

    View post on imgur.com

    View post on imgur.com

    Thank you for sticking with this. I use your plugin on many sites successfully and very much appreciate its benefits.
    I can give you access to the back end if that would help you analyze the issue.

    Plugin Contributor iSaumya

    (@isaumya)

    In the cache rule name=value means cookie_name=cookie_value. Don’t use the equals. Use something else where you don’t have to specify the cookie value. Try that and let me know.

    Thread Starter thartl

    (@hartl)

    Great call, Saumya.
    Switching from cookie equals admin_device=1
    to cookie contains admin_device made it work.

    I very much appreciate all your help and will be checking out Optimole for our future image optimization needs.

    Have a great day!

    Plugin Contributor iSaumya

    (@isaumya)

    Hi @hartl,
    It is so lovely to hear that finally, things are working great as you wanted. Please consider sharing a review in the review section of the plugin. ??

    Thread Starter thartl

    (@hartl)

    Certainly – done ??

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Setting “Bypass cache for the following cookies” not working as expected’ is closed to new replies.