pub struct CacheHandle<'a> {
pub cache: &'a Cache,
pub config: CacheHandleConfig,
}Expand description
A wrapper around a Cache for optional security features provided by CacheHandleConfig.
Unlike Cache, which is intended to be shared between Jobs, CacheHandles are intended to be made on a per-Job basis using the CacheHandleConfig appropriate for each particular Job.
For example, a CLI program writing results to a file doesn’t need to enable cache delay/unthreading, but a userscript should.
§Examples
use url_cleaner_engine::glue::*;
use std::time::Duration;
let cache = CacheHandle {
cache: &Default::default(),
config: Default::default()
};
assert_eq!(cache.read(CacheEntryKeys { subject: "subject", key: "key" }).unwrap().map(|entry| entry.value), None);
cache.write(NewCacheEntry { subject: "subject", key: "key", value: None, duration: Default::default() }).unwrap();
assert_eq!(cache.read(CacheEntryKeys { subject: "subject", key: "key" }).unwrap().map(|entry| entry.value), Some(None));
cache.write(NewCacheEntry { subject: "subject", key: "key", value: Some("value"), duration: Default::default() }).unwrap();
assert_eq!(cache.read(CacheEntryKeys { subject: "subject", key: "key" }).unwrap().map(|entry| entry.value), Some(Some("value".into())));Fields§
§cache: &'a CacheThe Cache.
config: CacheHandleConfigThe CacheHandleConfig.
Implementations§
Source§impl CacheHandle<'_>
impl CacheHandle<'_>
Sourcepub fn read(
&self,
keys: CacheEntryKeys<'_>,
) -> Result<Option<CacheEntryValues>, ReadFromCacheError>
pub fn read( &self, keys: CacheEntryKeys<'_>, ) -> Result<Option<CacheEntryValues>, ReadFromCacheError>
Reads from the cache.
§Errors
If the call to InnerCache::read returns an error, that error is returned.
§Panics
If, somehow, rand::rngs::OsRng doesn’t work, this panics when Self::config’s CacheHandleConfig::delay is true.
Sourcepub fn write(&self, entry: NewCacheEntry<'_>) -> Result<(), WriteToCacheError>
pub fn write(&self, entry: NewCacheEntry<'_>) -> Result<(), WriteToCacheError>
Writes to the cache.
If an entry for the subject and key already exists, overwrites it.
§Errors
If the call to InnerCache::write returns an error, that error is returned.
Trait Implementations§
Source§impl<'a> Clone for CacheHandle<'a>
impl<'a> Clone for CacheHandle<'a>
Source§fn clone(&self) -> CacheHandle<'a>
fn clone(&self) -> CacheHandle<'a>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<'a> Debug for CacheHandle<'a>
impl<'a> Debug for CacheHandle<'a>
impl<'a> Copy for CacheHandle<'a>
Auto Trait Implementations§
impl<'a> Freeze for CacheHandle<'a>
impl<'a> !RefUnwindSafe for CacheHandle<'a>
impl<'a> Send for CacheHandle<'a>
impl<'a> Sync for CacheHandle<'a>
impl<'a> Unpin for CacheHandle<'a>
impl<'a> !UnwindSafe for CacheHandle<'a>
Blanket Implementations§
Source§impl<T> AggregateExpressionMethods for T
impl<T> AggregateExpressionMethods for T
Source§fn aggregate_distinct(self) -> Self::Outputwhere
Self: DistinctDsl,
fn aggregate_distinct(self) -> Self::Outputwhere
Self: DistinctDsl,
DISTINCT modifier for aggregate functions Read moreSource§fn aggregate_all(self) -> Self::Outputwhere
Self: AllDsl,
fn aggregate_all(self) -> Self::Outputwhere
Self: AllDsl,
ALL modifier for aggregate functions Read moreSource§fn aggregate_filter<P>(self, f: P) -> Self::Output
fn aggregate_filter<P>(self, f: P) -> Self::Output
Source§fn aggregate_order<O>(self, o: O) -> Self::Outputwhere
Self: OrderAggregateDsl<O>,
fn aggregate_order<O>(self, o: O) -> Self::Outputwhere
Self: OrderAggregateDsl<O>,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
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> IntoSql for T
impl<T> IntoSql for T
Source§fn into_sql<T>(self) -> Self::Expression
fn into_sql<T>(self) -> Self::Expression
self to an expression for Diesel’s query builder. Read moreSource§fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
&self to an expression for Diesel’s query builder. Read more