pub struct Cache { /* private fields */ }Expand description
The cache handle. Cheap to clone: every clone is the same cache.
Implementations§
Source§impl Cache
impl Cache
Sourcepub fn new(
values: impl ValueStore + 'static,
signals: impl Signals + 'static,
) -> Self
pub fn new( values: impl ValueStore + 'static, signals: impl Signals + 'static, ) -> Self
A cache over the given stores.
Sourcepub fn local() -> Self
pub fn local() -> Self
A cache for one process: values in memory, generations and locks in memory too, nothing shared. For tests, tools and an application assembled without the bootstrap.
Sourcepub fn allow(&self, namespace: impl Into<String>)
pub fn allow(&self, namespace: impl Into<String>)
Registers a namespace, so values may depend on it and writes bump it. Registering one twice is nothing.
Sourcepub fn is_allowed(&self, namespace: &str) -> bool
pub fn is_allowed(&self, namespace: &str) -> bool
Whether the namespace is registered or in the record family.
Sourcepub fn namespaces(&self) -> Vec<String>
pub fn namespaces(&self) -> Vec<String>
The registered namespaces, sorted.
Sourcepub async fn get(&self, key: &str) -> Option<Vec<u8>>
pub async fn get(&self, key: &str) -> Option<Vec<u8>>
The value under key while every namespace it depends on is at the
generation it was stored at. A store failure reads as a miss and is
logged.
Sourcepub async fn put(
&self,
key: &str,
bytes: Vec<u8>,
deps: &[&str],
ttl: Duration,
) -> CoreResult<()>
pub async fn put( &self, key: &str, bytes: Vec<u8>, deps: &[&str], ttl: Duration, ) -> CoreResult<()>
Stores bytes under key for ttl, built from deps. An
unregistered namespace in deps is refused; a store failure is
logged and the value is simply not kept.
Sourcepub async fn add(
&self,
key: &str,
bytes: Vec<u8>,
deps: &[&str],
ttl: Duration,
) -> CoreResult<bool>
pub async fn add( &self, key: &str, bytes: Vec<u8>, deps: &[&str], ttl: Duration, ) -> CoreResult<bool>
Like Cache::put, only when nothing is under key; true when
this call stored it.
Sourcepub async fn forget(&self, key: &str) -> bool
pub async fn forget(&self, key: &str) -> bool
Drops the value under key; true when one was there.
Sourcepub async fn flush(&self)
pub async fn flush(&self)
Drops every value this process’s store holds. Other processes keep
theirs; Cache::bump_all reaches them.
Sourcepub async fn get_json<T: DeserializeOwned>(&self, key: &str) -> Option<T>
pub async fn get_json<T: DeserializeOwned>(&self, key: &str) -> Option<T>
The JSON value under key, decoded as T.
Sourcepub async fn put_json<T: Serialize + ?Sized>(
&self,
key: &str,
value: &T,
deps: &[&str],
ttl: Duration,
) -> CoreResult<()>
pub async fn put_json<T: Serialize + ?Sized>( &self, key: &str, value: &T, deps: &[&str], ttl: Duration, ) -> CoreResult<()>
Stores value as JSON under key.
Sourcepub async fn remember<T, F, Fut>(
&self,
key: &str,
ttl: Duration,
deps: &[&str],
load: F,
) -> CoreResult<T>
pub async fn remember<T, F, Fut>( &self, key: &str, ttl: Duration, deps: &[&str], load: F, ) -> CoreResult<T>
The value under key, or what load returns, stored for ttl and
built from deps. Concurrent callers for one key share one load.
Sourcepub fn current(&self, namespace: &str) -> Option<u64>
pub fn current(&self, namespace: &str) -> Option<u64>
The namespace’s generation as this process last saw it, or None
before it was ever read here.
Sourcepub async fn generation(&self, namespace: &str) -> CoreResult<u64>
pub async fn generation(&self, namespace: &str) -> CoreResult<u64>
The namespace’s generation, seeded when new.
Sourcepub async fn bump(&self, namespace: &str) -> CoreResult<u64>
pub async fn bump(&self, namespace: &str) -> CoreResult<u64>
Moves the namespace on: every value built from it misses from now. Returns the new generation. A failure is logged as well as returned, since the write it follows already stands.
Sourcepub async fn bump_all(&self) -> CoreResult<usize>
pub async fn bump_all(&self) -> CoreResult<usize>
Bumps every namespace the shared store knows and drops this process’s values. Returns how many namespaces moved.
Sourcepub async fn known(&self) -> CoreResult<Vec<(String, u64)>>
pub async fn known(&self) -> CoreResult<Vec<(String, u64)>>
Every namespace the shared store knows, with its generation.
Sourcepub async fn refresh(&self) -> CoreResult<()>
pub async fn refresh(&self) -> CoreResult<()>
Brings in the other processes’ bumps.
Sourcepub fn start_polling(&self, every: Duration) -> JoinHandle<()> ⓘ
pub fn start_polling(&self, every: Duration) -> JoinHandle<()> ⓘ
Refreshes every every, for the life of the process.
Sourcepub async fn lock(&self, name: &str, ttl: Duration) -> CoreResult<Option<Lock>>
pub async fn lock(&self, name: &str, ttl: Duration) -> CoreResult<Option<Lock>>
Takes the named lock for ttl, or None while another holder has
it. Release it with Lock::release; it lapses on its own after
ttl.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Cache
impl !UnwindSafe for Cache
impl Freeze for Cache
impl Send for Cache
impl Sync for Cache
impl Unpin for Cache
impl UnsafeUnpin 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
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> 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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more