leveldb/database/
cache.rs

1//! Structs and traits to work with the leveldb cache.
2use leveldb_sys::{leveldb_cache_t, leveldb_cache_create_lru, leveldb_cache_destroy};
3use libc::size_t;
4
5#[allow(missing_docs)]
6struct RawCache {
7    ptr: *mut leveldb_cache_t,
8}
9
10impl Drop for RawCache {
11    fn drop(&mut self) {
12        unsafe {
13            leveldb_cache_destroy(self.ptr);
14        }
15    }
16}
17
18/// Represents a leveldb cache
19pub struct Cache {
20    raw: RawCache,
21}
22
23impl Cache {
24    /// Create a leveldb LRU cache of a given size
25    pub fn new(size: size_t) -> Cache {
26        let cache = unsafe { leveldb_cache_create_lru(size) };
27        Cache { raw: RawCache { ptr: cache } }
28    }
29
30    #[allow(missing_docs)]
31    pub fn raw_ptr(&self) -> *mut leveldb_cache_t {
32        self.raw.ptr
33    }
34}