Skip to main content

Cache

Struct Cache 

Source
pub struct Cache { /* private fields */ }
Expand description

The cache handle. Cheap to clone: every clone is the same cache.

Implementations§

Source§

impl Cache

Source

pub fn new( values: impl ValueStore + 'static, signals: impl Signals + 'static, ) -> Self

A cache over the given stores.

Source

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.

Source

pub fn store(&self) -> &'static str

The configured value store’s name.

Source

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.

Source

pub fn is_allowed(&self, namespace: &str) -> bool

Whether the namespace is registered or in the record family.

Source

pub fn namespaces(&self) -> Vec<String>

The registered namespaces, sorted.

Source

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.

Source

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.

Source

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.

Source

pub async fn forget(&self, key: &str) -> bool

Drops the value under key; true when one was there.

Source

pub async fn flush(&self)

Drops every value this process’s store holds. Other processes keep theirs; Cache::bump_all reaches them.

Source

pub async fn get_json<T: DeserializeOwned>(&self, key: &str) -> Option<T>

The JSON value under key, decoded as T.

Source

pub async fn put_json<T: Serialize + ?Sized>( &self, key: &str, value: &T, deps: &[&str], ttl: Duration, ) -> CoreResult<()>

Stores value as JSON under key.

Source

pub async fn remember<T, F, Fut>( &self, key: &str, ttl: Duration, deps: &[&str], load: F, ) -> CoreResult<T>
where T: Serialize + DeserializeOwned, F: FnOnce() -> Fut, Fut: Future<Output = 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.

Source

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.

Source

pub async fn generation(&self, namespace: &str) -> CoreResult<u64>

The namespace’s generation, seeded when new.

Source

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.

Source

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.

Source

pub async fn known(&self) -> CoreResult<Vec<(String, u64)>>

Every namespace the shared store knows, with its generation.

Source

pub async fn refresh(&self) -> CoreResult<()>

Brings in the other processes’ bumps.

Source

pub fn start_polling(&self, every: Duration) -> JoinHandle<()> ⓘ

Refreshes every every, for the life of the process.

Source

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§

Source§

impl Clone for Cache

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Cache

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more