pub struct Cache { /* private fields */ }
Expand description
A cache for a given namespace.
Implementations§
Source§impl Cache
impl Cache
Sourcepub async fn get_property<T: FromStr>(&self, key: &str) -> Option<T>
pub async fn get_property<T: FromStr>(&self, key: &str) -> Option<T>
Sourcepub async fn add_listener(&self, listener: EventListener)
pub async fn add_listener(&self, listener: EventListener)
Adds an event listener to the cache.
Listeners are closures that will be called when the cache is successfully refreshed.
The listener will receive a Result<Value, Error>
, which will be Ok(new_config)
containing the newly fetched configuration.
The listener is a callback function that conforms to the EventListener
type alias:
Arc<dyn Fn(Result<Value, Error>) + Send + Sync>
.
Value
isserde_json::Value
representing the full configuration for the namespace.Error
iscrate::cache::Error
indicating a failure during the refresh process.
Listeners are called when the cache is successfully refreshed with new configuration, or when an error occurs during a refresh attempt.
§Arguments
listener
- The event listener to register. It must be anArc
-wrapped, thread-safe closure (Send + Sync
).
§Example
ⓘ
use std::sync::Arc;
use serde_json::Value;
use apollo_rust_client::cache::{Cache, Error, EventListener};
// Assuming `cache` is an existing Arc<Cache> instance
let listener: EventListener = Arc::new(|result: Result<Value, Error>| {
match result {
Ok(config) => println!("Cache refreshed, new config: {:?}", config),
Err(e) => println!("Cache refresh failed: {:?}", e),
}
});
cache.add_listener(listener).await;
Trait Implementations§
Source§impl FromWasmAbi for Cache
impl FromWasmAbi for Cache
Source§impl IntoWasmAbi for Cache
impl IntoWasmAbi for Cache
Source§impl LongRefFromWasmAbi for Cache
impl LongRefFromWasmAbi for Cache
Source§impl OptionFromWasmAbi for Cache
impl OptionFromWasmAbi for Cache
Source§impl OptionIntoWasmAbi for Cache
impl OptionIntoWasmAbi for Cache
Source§impl RefFromWasmAbi for Cache
impl RefFromWasmAbi for Cache
Source§impl RefMutFromWasmAbi for Cache
impl RefMutFromWasmAbi for Cache
Source§impl TryFromJsValue for Cache
impl TryFromJsValue for Cache
Source§impl VectorFromWasmAbi for Cache
impl VectorFromWasmAbi for Cache
Source§impl VectorIntoWasmAbi for Cache
impl VectorIntoWasmAbi for Cache
impl SupportsConstructor for Cache
impl SupportsInstanceProperty for Cache
impl SupportsStaticProperty for Cache
Auto Trait Implementations§
impl Freeze for Cache
impl !RefUnwindSafe for Cache
impl Send for Cache
impl Sync for Cache
impl Unpin for Cache
impl !UnwindSafe for Cache
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> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
Source§type Abi = <T as IntoWasmAbi>::Abi
type Abi = <T as IntoWasmAbi>::Abi
Same as
IntoWasmAbi::Abi
Source§fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
Same as
IntoWasmAbi::into_abi
, except that it may throw and never
return in the case of Err
.