-
Notifications
You must be signed in to change notification settings - Fork 217
Use database cache for all customer payment methods #4570
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Use database cache for all customer payment methods #4570
Conversation
…ment_method() to use get_all_payment_methods()
…tion_payment_method() to use get_all_payment_methods()" This reverts commit c622d76.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR improves payment method caching by replacing WordPress transients with the WC_Stripe_Database_Cache
for storing all customer payment methods, while maintaining backward compatibility for individual payment method type caches.
- Migrates the
get_all_payment_methods()
caching from WordPress transients toWC_Stripe_Database_Cache
- Refactors cache clearing logic to use a static method that can be called from API operations
- Adds automatic cache invalidation when payment methods are attached or detached from customers
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
includes/class-wc-stripe-customer.php | Updates caching mechanism and adds static cache clearing method |
includes/class-wc-stripe-api.php | Adds cache invalidation calls after successful payment method operations |
readme.txt | Documents the caching improvements in changelog |
changelog.txt | Documents the caching improvements in changelog |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Related to #4567
Changes proposed in this Pull Request:
As per the discussion in #4567, this PR builds on the code from that PR to use
WC_Stripe_Database_Cache
instead of built-in WordPress transients. I initially kept this work separate as we didn't have a mechanism to clean up stale entries in the database cache, but we addressed that shortcoming in #4609, which was merged earlier this week.At an implementation level, this PR does the following:
WC_Stripe_Customer::clear_customer_cache()
method, which clears the transients and the all-payments database cacheWC_Stripe_Customer->clear_cache()
method to call the new static functionWC_Stripe_API::attach_payment_method_to_customer()
andWC_Stripe_API::detach_payment_method_from_customer()
to call the new static cache clear function when the APIs don't return an errorattach_payment_to_customer()
without clearing the cache -- seewoocommerce-gateway-stripe/includes/payment-methods/class-wc-stripe-upe-payment-gateway.php
Lines 2517 to 2519 in f06e518
attach_source()
,delete_source()
, anddetach_payment_method()
methods inWC_Stripe_Customer
to clear their local customer data instead of clearing their full cacheattach_source()
was not there beforeConcerns
Given that this cache is going to be more durable, I am not 100% sure that we have all the use cases covered for saving a new payment method, especially because the
POST /v1/payment_methods
API call is made directly from the front-end, and we only get the payment method ID and make a decision about saving the payment method in Woo later.Testing instructions
The best approach will be to follow the testing instructions from #4567.
Changelog entry
Changelog Entry Comment
Comment
Post merge