Yoast\WP\SEO\Schema_Aggregator\Application\Cache

Manager::invalidatepublicYoast 1.0

Invalidate cache for specific page/per_page combination or all pages

Note: When invalidating a specific page without per_page, this clears ALL per_page variations for that page using a wildcard pattern.

Метод класса: Manager{}

Хуков нет.

Возвращает

true|false. Success.

Использование

$Manager = new Manager();
$Manager->invalidate( $post_type, ?int $page, ?int $per_page ): bool;
$post_type(строка) (обязательный)
The post type that the cache is for.
?int $page
.
По умолчанию: null
?int $per_page
.
По умолчанию: null

Код Manager::invalidate() Yoast 28.3

public function invalidate( string $post_type, ?int $page = null, ?int $per_page = null ): bool {
	if ( $page !== null && $per_page !== null ) {
		// Clear specific page/per_page combination.
		return \delete_transient( $this->get_cache_key( $post_type, $page, $per_page ) );
	}

	if ( $page !== null && $per_page === null ) {
		// Clear all per_page variations for this page.
		global $wpdb;

		if ( ! isset( $wpdb ) || ! \is_object( $wpdb ) ) {
			return false;
		}

		$pattern         = '_transient_' . self::CACHE_PREFIX . '_page_' . $page . '_per_%';
		$timeout_pattern = '_transient_timeout_' . self::CACHE_PREFIX . '_page_' . $page . '_per_%';
		// phpcs:ignore WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.DirectQuery
		$deleted = $wpdb->query(
			$wpdb->prepare(
				"DELETE FROM {$wpdb->options} WHERE option_name LIKE %s OR option_name LIKE %s",
				$pattern,
				$timeout_pattern,
			),
		);

		return $deleted !== false;
	}
	return $this->invalidate_all();
}