pub struct InnerCache { /* private fields */ }Expand description
A lazily connected connection to a Sqlite database.
§Examples
use url_cleaner_engine::glue::*;
use std::time::Duration;
// Note the mutability.
let mut cache = InnerCache::new(CachePath::Memory);
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())));Implementations§
Source§impl InnerCache
impl InnerCache
Sourcepub fn connection(&mut self) -> Option<&mut SqliteConnection>
pub fn connection(&mut self) -> Option<&mut SqliteConnection>
Gets the connection itself, if self has been connected via Self::connect yet.
Sourcepub fn connect(&mut self) -> Result<&mut SqliteConnection, ConnectCacheError>
pub fn connect(&mut self) -> Result<&mut SqliteConnection, ConnectCacheError>
Returns the connection, connecting if not already connected.
§Errors
If the call to std::fs::exists to check if the database exists returns an error, that error is returned.
If the call to std::fs::File::create_new to create the database returns an error, that error is returned.
If the call to SqliteConnection::establish to connect to the database returns an error, that error is returned.
If the call to SqlQuery::execute to initialize the database returns an error, that error is returned.
Sourcepub fn disconnect(&mut self)
pub fn disconnect(&mut self)
Disconnects from the database.
Sourcepub fn read(
&mut self,
keys: CacheEntryKeys<'_>,
) -> Result<Option<CacheEntryValues>, ReadFromCacheError>
pub fn read( &mut self, keys: CacheEntryKeys<'_>, ) -> Result<Option<CacheEntryValues>, ReadFromCacheError>
Reads from the database.
§Errors
If the call to Self::connect returns an error, that error is returned.
If the call to RunQueryDsl::load returns an error, that error is returned.
Sourcepub fn write(
&mut self,
entry: NewCacheEntry<'_>,
) -> Result<(), WriteToCacheError>
pub fn write( &mut self, entry: NewCacheEntry<'_>, ) -> Result<(), WriteToCacheError>
Writes to the database, overwriting the entry the equivalent call to Self::read would return.
§Errors
If the call to Self::connect returns an error, that error is returned.
If the call to RunQueryDsl::get_result returns an error, that error is returned.
Trait Implementations§
Source§impl Debug for InnerCache
impl Debug for InnerCache
Source§impl Default for InnerCache
impl Default for InnerCache
Source§fn default() -> InnerCache
fn default() -> InnerCache
Source§impl From<CachePath> for InnerCache
impl From<CachePath> for InnerCache
Source§impl From<InnerCache> for (CachePath, OnceCell<SqliteConnection>)
impl From<InnerCache> for (CachePath, OnceCell<SqliteConnection>)
Source§fn from(value: InnerCache) -> Self
fn from(value: InnerCache) -> Self
Source§impl From<InnerCache> for Cache
impl From<InnerCache> for Cache
Source§fn from(value: InnerCache) -> Self
fn from(value: InnerCache) -> Self
Source§impl PartialEq for InnerCache
impl PartialEq for InnerCache
impl Eq for InnerCache
Auto Trait Implementations§
impl !Freeze for InnerCache
impl !RefUnwindSafe for InnerCache
impl Send for InnerCache
impl !Sync for InnerCache
impl Unpin for InnerCache
impl !UnwindSafe for InnerCache
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> 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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.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