pub trait StatementCacheStrategy<DB, Statement>{
// 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§
Sourcefn cache_size(&self) -> CacheSize
fn cache_size(&self) -> CacheSize
Returns which prepared statement cache size is implemented by this trait
Sourcefn 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>
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).