[−][src]Struct blip::service::cache::Cache
This is supported on
feature="cache"
only.A distributed binary cache. May be used standalone, or added to a Mesh to operate in networked mode.
Examples
use blip::service::Cache; use std::sync::atomic::{AtomicUsize, Ordering::SeqCst}; let loads = AtomicUsize::new(0); let c = Cache::from_fn(32, move |key| { assert_eq!(0, loads.swap(1, SeqCst)); key.into() }); let val = c.get("test key").await?; assert_eq!(&*val, b"test key"); let val = c.get("test key").await?; assert_eq!(&*val, b"test key");
Implementations
impl Cache
[src]
pub fn new<S: Source>(max_keys: usize, source: S) -> Self
[src]
This is supported on
feature="cache"
only.Create a new cache from a Source. At most max_keys + (max_keys / 8)
keys will be
cached locally at any point in time.
Panics
Panics if max_keys == 0
.
Examples
use blip::service::{cache::Source, Cache}; use tonic::Status; struct Echo; #[blip::async_trait] impl Source for Echo { async fn get(&self, key: &[u8]) -> Result<Vec<u8>, Status> { Ok(key.into()) } } let cache = Cache::new(1024, Echo);
pub fn from_fn<F>(max_keys: usize, source: F) -> Self where
F: Sync + Send + 'static + Fn(&[u8]) -> Vec<u8>,
[src]
F: Sync + Send + 'static + Fn(&[u8]) -> Vec<u8>,
This is supported on
feature="cache"
only.Create a new cache from a source Fn
. At most max_keys + (max_keys / 8)
keys will
be cached locally at any point in time.
Panics
Panics if max_keys == 0
.
Examples
use blip::service::Cache; let cache = Cache::from_fn(1024, |key| key.into());
pub async fn get<'_, K: Into<Bytes>>(&'_ self, key: K) -> Result<Bytes, Status>
[src]
This is supported on
feature="cache"
only.Retrieve the value associated with key
.
Trait Implementations
impl<S: ?Sized> Clone for Cache<S>
[src]
fn clone(&self) -> Self
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl ExposedService for Cache
[src]
fn add_metadata<K: Extend<(String, Vec<u8>)>>(&self, keys: &mut K)
[src]
type Service = CacheServer<Self>
The service implementation.
fn into_service(self) -> Self::Service
[src]
impl MeshService for Cache
[src]
Auto Trait Implementations
impl<S = dyn Source + 'static> !RefUnwindSafe for Cache<S>
impl<S: ?Sized> Send for Cache<S> where
S: Send + Sync,
S: Send + Sync,
impl<S: ?Sized> Sync for Cache<S> where
S: Send + Sync,
S: Send + Sync,
impl<S: ?Sized> Unpin for Cache<S>
impl<S = dyn Source + 'static> !UnwindSafe for Cache<S>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T> Instrument for T
[src]
fn instrument(self, span: Span) -> Instrumented<Self>
[src]
fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> IntoRequest<T> for T
[src]
fn into_request(self) -> Request<T>
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,
fn vzip(self) -> V
impl<T> WithSubscriber for T
[src]
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
[src]
S: Into<Dispatch>,