pub struct InnerCache { /* private fields */ }Expand description
A lazily connected connection to the cache database.
§Examples
use url_cleaner_engine::glue::*;
// Note the mutability.
let mut cache = InnerCache::new(CachePath::Memory);
assert_eq!(cache.read("category", "key").unwrap(), None);
cache.write("category", "key", None).unwrap();
assert_eq!(cache.read("category", "key").unwrap(), Some(None));
cache.write("category", "key", Some("value")).unwrap();
assert_eq!(cache.read("category", "key").unwrap(), 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,
category: &str,
key: &str,
) -> Result<Option<Option<String>>, ReadFromCacheError>
pub fn read( &mut self, category: &str, key: &str, ) -> Result<Option<Option<String>>, 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,
category: &str,
key: &str,
value: Option<&str>,
) -> Result<(), WriteToCacheError>
pub fn write( &mut self, category: &str, key: &str, value: Option<&str>, ) -> 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> 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<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> 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 moreSource§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