Add tokens cache

This commit is contained in:
Emili Castells Guasch 2024-08-06 10:44:54 +02:00
parent bea17db588
commit 54657ed649
7 changed files with 107 additions and 28 deletions

View file

@ -12,6 +12,8 @@ namespace WooCommerce\PayPalCommerce\Onboarding\Endpoint;
use Exception;
use Psr\Log\LoggerInterface;
use WooCommerce\PayPalCommerce\ApiClient\Authentication\PayPalBearer;
use WooCommerce\PayPalCommerce\ApiClient\Authentication\SdkClientToken;
use WooCommerce\PayPalCommerce\ApiClient\Authentication\UserIdToken;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\LoginSeller;
use WooCommerce\PayPalCommerce\ApiClient\Helper\Cache;
use WooCommerce\PayPalCommerce\ApiClient\Repository\PartnerReferralsData;
@ -76,6 +78,13 @@ class LoginSellerEndpoint implements EndpointInterface {
*/
protected $logger;
/**
* The client credentials cache.
*
* @var Cache
*/
private $client_credentials_cache;
/**
* LoginSellerEndpoint constructor.
*
@ -86,6 +95,7 @@ class LoginSellerEndpoint implements EndpointInterface {
* @param Settings $settings The Settings.
* @param Cache $cache The Cache.
* @param LoggerInterface $logger The logger.
* @param Cache $client_credentials_cache The client credentials cache.
*/
public function __construct(
RequestData $request_data,
@ -94,16 +104,18 @@ class LoginSellerEndpoint implements EndpointInterface {
PartnerReferralsData $partner_referrals_data,
Settings $settings,
Cache $cache,
LoggerInterface $logger
LoggerInterface $logger,
Cache $client_credentials_cache
) {
$this->request_data = $request_data;
$this->login_seller_production = $login_seller_production;
$this->login_seller_sandbox = $login_seller_sandbox;
$this->partner_referrals_data = $partner_referrals_data;
$this->settings = $settings;
$this->cache = $cache;
$this->logger = $logger;
$this->request_data = $request_data;
$this->login_seller_production = $login_seller_production;
$this->login_seller_sandbox = $login_seller_sandbox;
$this->partner_referrals_data = $partner_referrals_data;
$this->settings = $settings;
$this->cache = $cache;
$this->logger = $logger;
$this->client_credentials_cache = $client_credentials_cache;
}
/**
@ -175,6 +187,12 @@ class LoginSellerEndpoint implements EndpointInterface {
if ( $this->cache->has( PayPalBearer::CACHE_KEY ) ) {
$this->cache->delete( PayPalBearer::CACHE_KEY );
}
if ( $this->client_credentials_cache->has( UserIdToken::CACHE_KEY ) ) {
$this->client_credentials_cache->delete( UserIdToken::CACHE_KEY );
}
if ( $this->client_credentials_cache->has( SdkClientToken::CACHE_KEY ) ) {
$this->client_credentials_cache->delete( SdkClientToken::CACHE_KEY );
}
wp_schedule_single_event(
time() + 5,