diff --git a/Cargo.toml b/Cargo.toml index 7fecb53b..d14a7afb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ members = [ ] [workspace.package] -version = "0.13.1" +version = "0.14.0-dev" edition = "2021" rust-version = "1.81.0" repository = "https://github.com/foyer-rs/foyer" @@ -53,10 +53,10 @@ opentelemetry_0_26 = { package = "opentelemetry", version = "0.26" } prometheus-client_0_22 = { package = "prometheus-client", version = "0.22" } # foyer components -foyer-common = { version = "0.13.1", path = "foyer-common" } -foyer-memory = { version = "0.13.1", path = "foyer-memory" } -foyer-storage = { version = "0.13.1", path = "foyer-storage" } -foyer = { version = "0.13.1", path = "foyer" } +foyer-common = { version = "0.14.0-dev", path = "foyer-common" } +foyer-memory = { version = "0.14.0-dev", path = "foyer-memory" } +foyer-storage = { version = "0.14.0-dev", path = "foyer-storage" } +foyer = { version = "0.14.0-dev", path = "foyer" } [workspace.lints.rust] missing_docs = "warn" diff --git a/foyer-memory/src/eviction/test_utils.rs b/foyer-memory/src/eviction/test_utils.rs index dfc18c4e..da0f6c8a 100644 --- a/foyer-memory/src/eviction/test_utils.rs +++ b/foyer-memory/src/eviction/test_utils.rs @@ -16,9 +16,10 @@ use std::sync::Arc; use itertools::Itertools; -use super::{Eviction, Op}; -use crate::Record; - +use crate::{ + eviction::{Eviction, Op}, + record::Record, +}; #[expect(dead_code)] pub trait OpExt: Eviction { fn acquire_immutable(&self, record: &Arc>) { diff --git a/foyer-memory/src/prelude.rs b/foyer-memory/src/prelude.rs index d33ce8c5..e27a0290 100644 --- a/foyer-memory/src/prelude.rs +++ b/foyer-memory/src/prelude.rs @@ -19,5 +19,5 @@ pub use crate::{ error::{Error, Result}, eviction::{fifo::FifoConfig, lfu::LfuConfig, lru::LruConfig, s3fifo::S3FifoConfig, Eviction, Op}, raw::{FetchMark, FetchState, Weighter}, - record::{CacheHint, Record}, + record::CacheHint, }; diff --git a/foyer-memory/src/record.rs b/foyer-memory/src/record.rs index ef30c45c..446ca0a9 100644 --- a/foyer-memory/src/record.rs +++ b/foyer-memory/src/record.rs @@ -67,8 +67,9 @@ pub struct Record where E: Eviction, { - data: Option>, + data: Data, state: UnsafeCell, + /// Reference count used in the in-memory cache. refs: AtomicUsize, flags: AtomicU64, } @@ -81,11 +82,7 @@ where E: Eviction, { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - let mut s = f.debug_struct("Record"); - if let Some(data) = self.data.as_ref() { - s.field("hash", &data.hash); - } - s.finish() + f.debug_struct("Record").field("hash", &self.data.hash).finish() } } @@ -99,67 +96,36 @@ where /// Create a record with data. pub fn new(data: Data) -> Self { Record { - data: Some(data), + data, state: Default::default(), refs: AtomicUsize::new(0), flags: AtomicU64::new(0), } } - /// Create a record without data. - pub fn empty() -> Self { - Record { - data: None, - state: Default::default(), - refs: AtomicUsize::new(0), - flags: AtomicU64::new(0), - } - } - - /// Wrap the data in the record. - /// - /// # Safety - /// - /// Panics if the record is already wrapping data. - pub fn insert(&mut self, data: Data) { - assert!(self.data.replace(data).is_none()); - } - - /// Unwrap the inner data. - /// - /// # Safety - /// - /// Panics if the record is not wrapping data. - pub fn take(&mut self) -> Data { - self.state = Default::default(); - self.refs.store(0, Ordering::SeqCst); - self.flags.store(0, Ordering::SeqCst); - self.data.take().unwrap() - } - /// Get the immutable reference of the record key. pub fn key(&self) -> &E::Key { - &self.data.as_ref().unwrap().key + &self.data.key } /// Get the immutable reference of the record value. pub fn value(&self) -> &E::Value { - &self.data.as_ref().unwrap().value + &self.data.value } /// Get the immutable reference of the record hint. pub fn hint(&self) -> &E::Hint { - &self.data.as_ref().unwrap().hint + &self.data.hint } /// Get the record hash. pub fn hash(&self) -> u64 { - self.data.as_ref().unwrap().hash + self.data.hash } /// Get the record weight. pub fn weight(&self) -> usize { - self.data.as_ref().unwrap().weight + self.data.weight } /// Get the record state wrapped with [`UnsafeCell`].