Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
rok committed Nov 19, 2023
1 parent cb6e32b commit 336140f
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions rust/lance/src/index/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use std::sync::Arc;

use lance_index::scalar::ScalarIndex;
use moka::sync::{Cache, ConcurrentCacheExt};
use moka::sync::{Cache, CacheBuilder, ConcurrentCacheExt};

use super::vector::VectorIndex;

Expand Down Expand Up @@ -46,9 +46,21 @@ pub struct IndexCache {

impl IndexCache {
pub(crate) fn new(capacity: usize) -> Self {
// Element size is the size of the u32 key (4 bytes) + the size of the uuid (16 bytes)
let element_size : u32 = 20;


let vector_cache = CacheBuilder::new(capacity as u64)
.weigher(move |&_,&_| -> u32 { element_size })
.max_capacity(capacity as u64)
.build();

let scalar_cache = Arc::new(Cache::new(capacity as u64));
// let vector_cahce = Arc::new(Cache::new(capacity as u64));

Self {
scalar_cache: Arc::new(Cache::new(capacity as u64)),
vector_cache: Arc::new(Cache::new(capacity as u64)),
scalar_cache: scalar_cache,
vector_cache: Arc::new(vector_cache),
cache_stats: Arc::new(CacheStats::default()),
}
}
Expand All @@ -65,6 +77,12 @@ impl IndexCache {
self.scalar_cache.entry_count() as usize + self.vector_cache.entry_count() as usize
}

pub(crate) fn get_byte_size(&self) {
self.scalar_cache.sync();
self.vector_cache.sync();
self.vector_cache.weighted_size();
}

/// Get an Index if present. Otherwise returns [None].
pub(crate) fn get_scalar(&self, key: &str) -> Option<Arc<dyn ScalarIndex>> {
self.scalar_cache.get(key)
Expand Down

0 comments on commit 336140f

Please sign in to comment.