pub struct SchemaCache { /* private fields */ }Expand description
A cache for SchemaSnapshot values keyed by version + source.
§Examples
use vlorql_core::cache::SchemaCache;
use vlorql_core::schema::{SchemaSnapshot, SchemaMetadata, DataType, TableSchema, ColumnSchema};
use std::sync::Arc;
let cache = SchemaCache::new(10, 60);
let schema = Arc::new(SchemaSnapshot::new(vec![], SchemaMetadata::default()));
let key = vlorql_core::cache::SchemaCacheKey {
version: "v1".to_owned(),
source: "test".to_owned(),
};
// Insert a value and retrieve it.
let loaded = cache.get_or_insert_with(key.clone(), || async {
Arc::clone(&schema)
}).await;
assert_eq!(loaded.table_count(), 0);Implementations§
Source§impl SchemaCache
impl SchemaCache
Sourcepub fn new(capacity: u64, ttl_seconds: u64) -> Self
pub fn new(capacity: u64, ttl_seconds: u64) -> Self
Creates a new schema cache.
capacity— maximum number of entries before the cache evicts least-recently-used items.ttl_seconds— time-to-live in seconds. Entries older than this are automatically invalidated.
§Examples
use vlorql_core::cache::SchemaCache;
let cache = SchemaCache::new(100, 300);
assert_eq!(cache.inner_size(), 0);Sourcepub async fn get_or_insert_with<F, Fut>(
&self,
key: SchemaCacheKey,
f: F,
) -> Arc<SchemaSnapshot> ⓘ
pub async fn get_or_insert_with<F, Fut>( &self, key: SchemaCacheKey, f: F, ) -> Arc<SchemaSnapshot> ⓘ
Returns the cached value for key, or inserts the value produced
by f and returns it.
The loader function f is only called when the key is not present
(or has expired). Because the underlying cache is concurrent,
concurrent callers for the same key are deduplicated: only one
f runs, and the others receive its result.
Sourcepub fn invalidate_version(&self, version: &str)
pub fn invalidate_version(&self, version: &str)
Removes all entries whose version matches version.
This is useful when a schema deployment bumps the version string and you want to drop stale snapshots without clearing the entire cache.
Sourcepub fn invalidate(&self, key: &SchemaCacheKey)
pub fn invalidate(&self, key: &SchemaCacheKey)
Removes the entry for a single key.
Sourcepub fn inner_size(&self) -> u64
pub fn inner_size(&self) -> u64
Returns the number of entries currently in the cache (alias for
size).
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 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for SchemaCache
impl !UnwindSafe for SchemaCache
impl Freeze for SchemaCache
impl Send for SchemaCache
impl Sync for SchemaCache
impl Unpin for SchemaCache
impl UnsafeUnpin 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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
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