journal_engine/cache.rs
1//! Cache types for journal file indexes
2
3use crate::facets::Facets;
4use foyer::HybridCache;
5use journal_index::{FieldName, FileIndex};
6use journal_registry::File;
7use serde::{Deserialize, Serialize};
8
9/// Cache version number. Increment this when the FileIndex or FileIndexKey
10/// schema changes to automatically invalidate old cache entries.
11///
12/// v2: File index semantics changed from earlier pre-release builds. Old cache
13/// entries are not reused across SDK versions with different index rules.
14const CACHE_VERSION: u32 = 2;
15
16/// Cache key for file indexes that includes the file, facets, source timestamp
17/// field, and cache version. Different facet configurations or timestamp fields
18/// produce different indexes, so all are needed to uniquely identify a cached
19/// index. The version ensures that schema changes automatically invalidate old
20/// cache entries.
21#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
22pub struct FileIndexKey {
23 version: u32,
24 pub file: File,
25 pub(crate) facets: Facets,
26 pub(crate) source_timestamp_field: Option<FieldName>,
27}
28
29impl FileIndexKey {
30 pub fn new(file: &File, facets: &Facets, source_timestamp_field: Option<FieldName>) -> Self {
31 Self {
32 version: CACHE_VERSION,
33 file: file.clone(),
34 facets: facets.clone(),
35 source_timestamp_field,
36 }
37 }
38}
39
40/// Type alias for file index cache using Foyer's HybridCache.
41pub type FileIndexCache = HybridCache<FileIndexKey, FileIndex>;