mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 13:44:42 +08:00
✨ Add new hook that clears API caches
This commit is contained in:
parent
f311ca615b
commit
e11441665e
2 changed files with 33 additions and 0 deletions
|
@ -840,6 +840,9 @@ return array(
|
|||
$container->get( 'wcgateway.settings' )
|
||||
);
|
||||
},
|
||||
'api.paypal-bearer-cache' => static function( ContainerInterface $container ): Cache {
|
||||
return new Cache( 'ppcp-paypal-bearer' );
|
||||
},
|
||||
'api.client-credentials-cache' => static function( ContainerInterface $container ): Cache {
|
||||
return new Cache( 'ppcp-client-credentials-cache' );
|
||||
},
|
||||
|
|
|
@ -20,6 +20,8 @@ use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ModuleClassNameI
|
|||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ServiceModule;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\Order;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Authentication\PayPalBearer;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Authentication\SdkClientToken;
|
||||
|
||||
/**
|
||||
* Class ApiModule
|
||||
|
@ -103,6 +105,34 @@ class ApiModule implements ServiceModule, ExtendingModule, ExecutableModule {
|
|||
2
|
||||
);
|
||||
|
||||
/**
|
||||
* Flushes the API client caches.
|
||||
*/
|
||||
add_action(
|
||||
'woocommerce_paypal_payments_flush_api_cache',
|
||||
static function () use ( $c ) {
|
||||
$caches = array(
|
||||
'api.paypal-bearer-cache' => array(
|
||||
PayPalBearer::CACHE_KEY,
|
||||
),
|
||||
'api.client-credentials-cache' => array(
|
||||
SdkClientToken::CACHE_KEY,
|
||||
),
|
||||
);
|
||||
|
||||
foreach ( $caches as $cache_id => $keys ) {
|
||||
$cache = $c->get( $cache_id );
|
||||
assert( $cache instanceof Cache );
|
||||
|
||||
foreach ( $keys as $key ) {
|
||||
if ( $cache->has( $key ) ) {
|
||||
$cache->delete( $key );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue