Describe the bug
If some form of object caching is in place, the woocommerce_setup_jetpack_opted_in gets updated at the start of the profiler, but does not correctly update wc_connect_options afterwards.
Reading woocommerce_setup_jetpack_opted_in returns false until the cache is flushed.
This issue was first noted on a Pressable site, which uses memcached, but appears to persist across different forms of object caching.
This may or may not have something to do with how this option is updated via the REST options endpoint that somehow bypasses the update_option check made by a caching function.
To Reproduce
Steps to reproduce the behavior:
wc_connect_options and woocommerce_setup_jetpack_opted_in from your wp_options table.Expected behavior
Expected the TOS option to be retrieved with the correct value and to allow usage of components that require its acceptance.
Screenshots

In W3 Total Cache, this appears to be the hook that checks for updates to options and should be flushing the cache - https://github.com/W3EDGE/w3-total-cache/blob/b80b957a5e8e139b1d104f4ef31f110732bb63cf/ObjectCache_Plugin.php#L83
After testing this a bit more, it looks like the problem here is that requests to non-admin URLs don't invalidate the object cache.
Prior to making any other updates that would invalidate cache, we can manually check that woocommerce_setup_jetpack_opted_in is set to 1 in the database, but retrieving this value via WP returns false so wc_connect_options is never properly set.
This may be a similar issue to the one we experience with Pressable, but planning on looking into that further. I imagine this may be an issue with a number of caching plugins. While, I feel that POST requests to REST APIs should be a potential trigger to flush the cache, it may be worth looking into adding a filter (if one exists for a given plugin) to invalidate cache upon hitting certain routes.
Tested this with a couple other caching plugins that make use of Memcached and Redis and did not encounter this issue. Those had cache mechanisms that ran on every request, regardless of whether or not it was an admin request, and updated the cache accordingly.
Had a Zoom chat with @timmyc about this and after some discussion it feels like trying to create workarounds for various plugins inside wc-admin will be hacky and result in more trouble than it's worth.
It may be worth considering opening PRs with the plugins causing this to offer a better fix.
Here are the most popular plugins with object caching.
Working
Not working
Thanks for the update and your persistence on this one Josh! So guessing the working caching plugins all have invalidation setup on REST POST/PUT/DELETE actions?
@timmyc Most of them don't distinguish at all between admin/non-admin/REST requests, which I think should be the case. It may be more overhead to watch for updated options in non-admin areas, but if a store has any methods which may update options via the front-end this should still invalidate cache.
If we want to limit "exposure" for performance reasons, I think that limiting to admin requests and POST/PUT/DELETE requests is a good strategy. Though I would be a little surprised if the update_option hook was having any significant impact on performance.
After being able to recreate this issue every time on Pressable, today I am no longer able to. Spun up a new Pressable site and things worked as expected with settings persisting on refresh without any need to flush the object cache. The same is true of an Atomic dev site.
I returned to my previously created site and using the same WC and WC admin versions where this bug was present and was not able to recreate the issue there either.
@pmcpinto Can you check to see if you're still hitting the issue you outlined in https://github.com/woocommerce/woocommerce-admin/issues/3151?
@pmcpinto Can you check to see if you're still hitting the issue you outlined in #3151?
Hey @joshuatf I just tested it in a brand new store and I'm getting the automated taxes message, so it's working smoothly.
Lets close this one out for now.