pub struct SchemaCache { /* private fields */ }Expand description
Fetches and caches Avro schemas by schema ID.
The cache is lock-free for reads via DashMap. Each schema is fetched
once from the Pub/Sub GetSchema RPC and cached for the lifetime of
the handler.
Implementations§
Source§impl SchemaCache
impl SchemaCache
Sourcepub fn get(&self, schema_id: &str) -> Option<Schema>
pub fn get(&self, schema_id: &str) -> Option<Schema>
Get a schema by ID if it is already in cache.
Sourcepub fn parse_and_insert(
&self,
schema_id: String,
schema_json: &str,
) -> Result<Schema>
pub fn parse_and_insert( &self, schema_id: String, schema_json: &str, ) -> Result<Schema>
Parse Avro schema JSON and store it in the cache.
Returns the parsed schema. Called after receiving schema_json from GetSchema.
Sourcepub async fn get_or_fetch(
&self,
schema_id: &str,
channel: &Channel,
metadata: MetadataMap,
) -> Result<Schema>
pub async fn get_or_fetch( &self, schema_id: &str, channel: &Channel, metadata: MetadataMap, ) -> Result<Schema>
Return the schema for schema_id from cache, or fetch it via the GetSchema RPC.
On a cache miss, calls GetSchema using the provided gRPC client and
authentication metadata. The fetched schema is parsed, inserted into the
cache, and returned.
§Errors
PubSubError::Transportif theGetSchemaRPC fails (e.g. schema not found).PubSubError::Avroif the returned schema JSON cannot be parsed.
Trait Implementations§
Source§impl Clone for SchemaCache
impl Clone for SchemaCache
Source§fn clone(&self) -> SchemaCache
fn clone(&self) -> SchemaCache
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for SchemaCache
impl Debug for SchemaCache
Auto Trait Implementations§
impl Freeze for SchemaCache
impl !RefUnwindSafe for SchemaCache
impl Send for SchemaCache
impl Sync for SchemaCache
impl Unpin for SchemaCache
impl UnsafeUnpin for SchemaCache
impl !UnwindSafe for SchemaCache
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request