pub struct Cached<T: ?Sized> { /* private fields */ }Expand description
A provider with its lookups and decisions kept for a short while.
It implements Directory and Authorizer for a provider that does, answering from memory
within the CacheOptions, and Accounts by delegating, clearing every kept answer when
an account is put or removed. It holds the provider in an Arc, so a host wraps a
loaded plugin’s handle. Debug shows counts only.
use std::sync::Arc;
use coqui_access::{Directory, Lookup, Person};
use coqui_access::guatiao::library::ProviderError;
use coqui_access_kit::{CacheOptions, Cached};
struct One;
impl Directory for One {
fn lookup(&self, lookup: Lookup) -> Result<Option<Person>, ProviderError> {
Ok((lookup.value == "alice").then(|| Person { id: "1".into(), ..Person::default() }))
}
}
let cached = Cached::new(Arc::new(One), CacheOptions::default());
let alice = Lookup { by: "name".into(), value: "alice".into(), ..Lookup::default() };
assert_eq!(cached.lookup(alice.clone()).unwrap().unwrap().id, "1");
cached.invalidate(&alice);Implementations§
Source§impl<T: ?Sized> Cached<T>
impl<T: ?Sized> Cached<T>
Sourcepub fn new(inner: Arc<T>, options: CacheOptions) -> Self
pub fn new(inner: Arc<T>, options: CacheOptions) -> Self
inner, with its answers kept as options say. Nothing is asked yet.
Sourcepub fn options(&self) -> CacheOptions
pub fn options(&self) -> CacheOptions
The options in force.
Sourcepub fn invalidate(&self, lookup: &Lookup)
pub fn invalidate(&self, lookup: &Lookup)
Forgets what is kept for lookup, so the next one asks the provider.
Sourcepub fn invalidate_all(&self)
pub fn invalidate_all(&self)
Forgets every lookup and decision kept.
Trait Implementations§
Source§impl<T: Accounts + ?Sized> Accounts for Cached<T>
impl<T: Accounts + ?Sized> Accounts for Cached<T>
Source§fn accounts(&self) -> Result<Vec<AccountInfo>, ProviderError>
fn accounts(&self) -> Result<Vec<AccountInfo>, ProviderError>
The accounts kept, without anything that proves one.
Source§fn put(&self, account: AccountPut) -> Result<PutOutcome, ProviderError>
fn put(&self, account: AccountPut) -> Result<PutOutcome, ProviderError>
Makes an account, or changes the one of that name; a field not said is left as it
is. A provider that makes secrets itself answers with the one it made.
Source§impl<T: Authorizer + ?Sized> Authorizer for Cached<T>
impl<T: Authorizer + ?Sized> Authorizer for Cached<T>
Evaluates the request using the supplied authoritative person record.
Auto Trait Implementations§
impl<T> !RefUnwindSafe for Cached<T>
impl<T> !UnwindSafe for Cached<T>
impl<T> Freeze for Cached<T>where
T: ?Sized,
impl<T> Send for Cached<T>
impl<T> Sync for Cached<T>
impl<T> Unpin for Cached<T>where
T: ?Sized,
impl<T> UnsafeUnpin for Cached<T>where
T: ?Sized,
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