pub struct MySqlCache { /* private fields */ }Available on crate feature
mysql only.Expand description
MySqlCache is a cache using mysql to store data.
It uses sqlx::MySqlPool to connect to mysql.
Feature mysql must be enabled.
§Prepare
Create a table named cache with the following schema:
CREATE TABLE IF NOT EXISTS cache (
name varchar(255) not null,
val text not null,
primary key (name)
);Note:
- You can change the table name and the field names.
- The
namefield (or whatever you specify) is the primary key of the cache.
§Build
Use MySqlCacheBuilder to build a MySqlCache.
You need to specify the table name and the field names when building.
ⓘ
let pool = MySqlPool::connect("mysql://test:123456@127.0.0.1:3306/dev").await?;
let cache = MySqlCacheBuilder::new(pool)
.table("cache")
.key_field("name")
.value_field("val")
.finish();Trait Implementations§
Source§impl Cache for MySqlCache
impl Cache for MySqlCache
fn get<'life0, 'life1, 'async_trait, T>( &'life0 self, key: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Option<T>>> + Send + 'async_trait>>
fn set<'life0, 'life1, 'async_trait, T>( &'life0 self, key: &'life1 str, value: T, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
fn delete<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn len<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<usize>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§impl Clone for MySqlCache
impl Clone for MySqlCache
Source§fn clone(&self) -> MySqlCache
fn clone(&self) -> MySqlCache
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for MySqlCache
impl !RefUnwindSafe for MySqlCache
impl Send for MySqlCache
impl Sync for MySqlCache
impl Unpin for MySqlCache
impl !UnwindSafe for MySqlCache
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
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 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>
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