25 lines
615 B
Rust
25 lines
615 B
Rust
use dashmap::DashMap;
|
|
|
|
pub struct StatementCache {
|
|
/// Maps a Cache Key (String) -> SQL String (String)
|
|
statements: DashMap<String, String>,
|
|
}
|
|
|
|
impl StatementCache {
|
|
pub fn new(_max_capacity: u64) -> Self {
|
|
Self {
|
|
statements: DashMap::new(),
|
|
}
|
|
}
|
|
|
|
/// Retrieve an existing statement name by key, or None if it missed
|
|
pub fn get(&self, key: &str) -> Option<String> {
|
|
self.statements.get(key).map(|v| v.clone())
|
|
}
|
|
|
|
/// Insert a completely verified/compiled statement string into the cache
|
|
pub fn insert(&self, key: String, sql: String) {
|
|
self.statements.insert(key, sql);
|
|
}
|
|
}
|