diesel::connection::statement_cache::strategy

Trait StatementCacheStrategy

Source
pub trait StatementCacheStrategy<DB, Statement>
where DB: Backend, StatementCacheKey<DB>: Hash + Eq,
{ // Required methods fn cache_size(&self) -> CacheSize; fn get( &mut self, key: StatementCacheKey<DB>, backend: &DB, source: &dyn QueryFragmentForCachedStatement<DB>, prepare_fn: &mut dyn FnMut(&str, bool) -> Result<Statement, Error>, ) -> Result<MaybeCached<'_, Statement>, Error>; }
Available on crate feature i-implement-a-third-party-backend-and-opt-into-breaking-changes only.
Expand description

Implement this trait, in order to control statement caching.

Required Methods§

Source

fn cache_size(&self) -> CacheSize

Returns which prepared statement cache size is implemented by this trait

Source

fn get( &mut self, key: StatementCacheKey<DB>, backend: &DB, source: &dyn QueryFragmentForCachedStatement<DB>, prepare_fn: &mut dyn FnMut(&str, bool) -> Result<Statement, Error>, ) -> Result<MaybeCached<'_, Statement>, Error>

Every query (which is safe to cache) will go through this function The implementation will decide whether to cache statement or not

  • prepare_fn - will be invoked if prepared statement wasn’t cached already
    • first argument is sql query string
    • second argument specifies whether statement will be cached (true) or not (false).

Implementors§

Source§

impl<DB, Statement> StatementCacheStrategy<DB, Statement> for WithCacheStrategy<DB, Statement>

Source§

impl<DB, Statement> StatementCacheStrategy<DB, Statement> for WithoutCacheStrategy