forked from vortex-data/vortex
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcache.rs
More file actions
31 lines (27 loc) · 1021 Bytes
/
cache.rs
File metadata and controls
31 lines (27 loc) · 1021 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright the Vortex contributors
use async_trait::async_trait;
use parking_lot::RwLock;
use vortex_buffer::ByteBuffer;
use vortex_error::VortexResult;
use vortex_layout::segments::SegmentCache;
use vortex_layout::segments::SegmentId;
use vortex_layout::segments::SharedSegmentCache;
use vortex_utils::aliases::hash_map::HashMap;
/// Segment cache containing the initial read segments.
pub struct InitialReadSegmentCache {
pub initial: RwLock<HashMap<SegmentId, ByteBuffer>>,
pub fallback: SharedSegmentCache,
}
#[async_trait]
impl SegmentCache for InitialReadSegmentCache {
async fn get(&self, id: SegmentId) -> VortexResult<Option<ByteBuffer>> {
if let Some(buffer) = self.initial.read().get(&id) {
return Ok(Some(buffer.clone()));
}
self.fallback.get(id).await
}
async fn put(&self, id: SegmentId, buffer: ByteBuffer) -> VortexResult<()> {
self.fallback.put(id, buffer).await
}
}