-
Notifications
You must be signed in to change notification settings - Fork 333
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LRU statement cache #61
Conversation
/// # Failure | ||
/// | ||
/// Will return `Err` if no cached statement can be found and the underlying SQLite prepare call fails. | ||
pub fn get(&mut self, sql: &str) -> Result<Statement<'conn>> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm inclined to think this should return a Result<CachedStatement<'cache>>
. CachedStatement
would wrap up Statement
(and implement Deref
/DerefMut
for it too, I think), and would return it to the cache in drop
. This would remove the need to remember to call release
. We could actually remove release
altogether, I think, and add a release
or discard
method to CachedStatement
that would (a) take self
(to consume it) and (b) set a flag (or something similar) to avoid returning the statement to the cache in drop
.
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, introducing a CachedStatement
is the right way.
I am sorry to bother you but I cannot make the CachedStatement work: |
Good news / bad news. Good news is you can get around the issues in pub struct CachedStatement<'conn> {
stmt: Option<Statement<'conn>>,
cache: RefCell<StatementCache<'conn>>,
pub cacheable : bool,
}
impl<'conn> Drop for CachedStatement<'conn> {
#[allow(unused_must_use)]
fn drop(&mut self) {
if self.cacheable {
self.cache.borrow_mut().release(self.stmt.take().unwrap(), false);
} else {
self.stmt.take().unwrap().finalize();
}
}
} Bad news is it looks like |
Thanks. |
I will need your help: how to create a
|
Mm, that's never going to work - if it did, you'd end up with multiple What if you put the internal cache itself inside a |
The implementation is not perfect but it seems to be working... |
test bench_cache ... bench: 124 ns/iter (+/- 76) |
…wenn-stmt-cache
statements from returning to the cache.
Merged as part of #113. |
No description provided.