Skip to content

Commit 844a27a

Browse files
committed
Add clear_type_cache to blocking client
1 parent 21e4dd7 commit 844a27a

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

postgres/src/client.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -501,8 +501,8 @@ impl Client {
501501
Notifications::new(self.connection.as_ref())
502502
}
503503

504-
/// Constructs a cancellation token that can later be used to request
505-
/// cancellation of a query running on this connection.
504+
/// Constructs a cancellation token that can later be used to request cancellation of a query running on this
505+
/// connection.
506506
///
507507
/// # Examples
508508
///
@@ -541,6 +541,15 @@ impl Client {
541541
CancelToken::new(self.client.cancel_token())
542542
}
543543

544+
/// Clears the client's type information cache.
545+
///
546+
/// When user-defined types are used in a query, the client loads their definitions from the database and caches
547+
/// them for the lifetime of the client. If those definitions are changed in the database, this method can be used
548+
/// to flush the local cache and allow the new, updated definitions to be loaded.
549+
pub fn clear_type_cache(&self) {
550+
self.client.clear_type_cache();
551+
}
552+
544553
/// Determines if the client's connection has already closed.
545554
///
546555
/// If this returns `true`, the client is no longer usable.

tokio-postgres/src/client.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ impl InnerClient {
113113
self.state.lock().types.insert(oid, type_.clone());
114114
}
115115

116-
pub fn clear_types(&self) {
116+
pub fn clear_type_cache(&self) {
117117
self.state.lock().types.clear();
118118
}
119119

@@ -180,11 +180,6 @@ impl Client {
180180
&self.inner
181181
}
182182

183-
/// Clears the cache of database types (domain, enum, composition) that are loaded when preparing a query.
184-
pub fn clear_types_cache(&self) {
185-
self.inner().clear_types()
186-
}
187-
188183
#[cfg(feature = "runtime")]
189184
pub(crate) fn set_socket_config(&mut self, socket_config: SocketConfig) {
190185
self.socket_config = Some(socket_config);
@@ -493,9 +488,8 @@ impl Client {
493488
TransactionBuilder::new(self)
494489
}
495490

496-
/// Constructs a cancellation token that can later be used to request
497-
/// cancellation of a query running on the connection associated with
498-
/// this client.
491+
/// Constructs a cancellation token that can later be used to request cancellation of a query running on the
492+
/// connection associated with this client.
499493
pub fn cancel_token(&self) -> CancelToken {
500494
CancelToken {
501495
#[cfg(feature = "runtime")]
@@ -532,6 +526,15 @@ impl Client {
532526
self.cancel_token().cancel_query_raw(stream, tls).await
533527
}
534528

529+
/// Clears the client's type information cache.
530+
///
531+
/// When user-defined types are used in a query, the client loads their definitions from the database and caches
532+
/// them for the lifetime of the client. If those definitions are changed in the database, this method can be used
533+
/// to flush the local cache and allow the new, updated definitions to be loaded.
534+
pub fn clear_type_cache(&self) {
535+
self.inner().clear_type_cache();
536+
}
537+
535538
/// Determines if the connection to the server has already closed.
536539
///
537540
/// In that case, all future queries will fail.

0 commit comments

Comments
 (0)