mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-07 19:54:15 +08:00
Merge branch 'trunk' into PCP-4439-check-the-branded-only-flag-when-settings-ui-is-loaded-the-first-time
This commit is contained in:
commit
c77f3266e8
2 changed files with 39 additions and 18 deletions
|
@ -113,23 +113,16 @@ class ApiModule implements ServiceModule, ExtendingModule, ExecutableModule {
|
||||||
'woocommerce_paypal_payments_flush_api_cache',
|
'woocommerce_paypal_payments_flush_api_cache',
|
||||||
static function () use ( $c ) {
|
static function () use ( $c ) {
|
||||||
$caches = array(
|
$caches = array(
|
||||||
'api.paypal-bearer-cache' => array(
|
'api.paypal-bearer-cache',
|
||||||
PayPalBearer::CACHE_KEY,
|
'api.client-credentials-cache',
|
||||||
),
|
'settings.service.signup-link-cache',
|
||||||
'api.client-credentials-cache' => array(
|
|
||||||
SdkClientToken::CACHE_KEY,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach ( $caches as $cache_id => $keys ) {
|
foreach ( $caches as $cache_id ) {
|
||||||
$cache = $c->get( $cache_id );
|
$cache = $c->get( $cache_id );
|
||||||
assert( $cache instanceof Cache );
|
assert( $cache instanceof Cache );
|
||||||
|
|
||||||
foreach ( $keys as $key ) {
|
$cache->flush();
|
||||||
if ( $cache->has( $key ) ) {
|
|
||||||
$cache->delete( $key );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
@ -50,6 +50,7 @@ class Cache {
|
||||||
*/
|
*/
|
||||||
public function has( string $key ) : bool {
|
public function has( string $key ) : bool {
|
||||||
$value = $this->get( $key );
|
$value = $this->get( $key );
|
||||||
|
|
||||||
return false !== $value;
|
return false !== $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,4 +75,31 @@ class Cache {
|
||||||
public function set( string $key, $value, int $expiration = 0 ) : bool {
|
public function set( string $key, $value, int $expiration = 0 ) : bool {
|
||||||
return (bool) set_transient( $this->prefix . $key, $value, $expiration );
|
return (bool) set_transient( $this->prefix . $key, $value, $expiration );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flushes all items of the current "cache group", i.e., items that use the defined prefix.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function flush() : void {
|
||||||
|
global $wpdb;
|
||||||
|
|
||||||
|
// Get a list of all transients with the relevant "group prefix" from the DB.
|
||||||
|
$transients = $wpdb->get_col(
|
||||||
|
$wpdb->prepare(
|
||||||
|
"SELECT option_name FROM $wpdb->options WHERE option_name LIKE %s",
|
||||||
|
$wpdb->esc_like( '_transient_' . $this->prefix ) . '%'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete each cache item individually to ensure WP can fire all relevant
|
||||||
|
* actions, perform checks and other cleanup tasks and ensures eventually
|
||||||
|
* object cache systems, like Redis, are kept in-sync with the DB.
|
||||||
|
*/
|
||||||
|
foreach ( $transients as $transient ) {
|
||||||
|
$key = str_replace( '_transient_' . $this->prefix, '', $transient );
|
||||||
|
$this->delete( $key );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue