diff --git a/foyer-storage/src/store.rs b/foyer-storage/src/store.rs index 73e1b91d..6539ac76 100644 --- a/foyer-storage/src/store.rs +++ b/foyer-storage/src/store.rs @@ -12,14 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use std::{ - any::{Any, TypeId}, - borrow::Cow, - fmt::Debug, - hash::Hash, - sync::Arc, - time::Instant, -}; +use std::{any::Any, borrow::Cow, fmt::Debug, hash::Hash, sync::Arc, time::Instant}; use equivalent::Equivalent; use foyer_common::{ @@ -313,7 +306,7 @@ where /// If the disk cache is enabled. pub fn is_enabled(&self) -> bool { - self.inner.engine.type_id() != TypeId::of::>>() + !(self.inner.engine.as_ref() as &dyn Any).is::>() } } diff --git a/foyer/src/hybrid/cache.rs b/foyer/src/hybrid/cache.rs index 179947f8..ad144bfe 100644 --- a/foyer/src/hybrid/cache.rs +++ b/foyer/src/hybrid/cache.rs @@ -1081,6 +1081,35 @@ mod tests { .unwrap() } + #[test_log::test(tokio::test)] + async fn test_is_hybrid_with_disk_cache() { + let dir = tempfile::tempdir().unwrap(); + + let cache = HybridCacheBuilder::::new() + .memory(1) + .storage() + .with_engine_config(BlockEngineConfig::new( + FsDeviceBuilder::new(dir).with_capacity(1).build().unwrap(), + )) + .build() + .await + .unwrap(); + + assert!(cache.is_hybrid()); + } + + #[test_log::test(tokio::test)] + async fn test_is_hybrid_without_disk_cache() { + let cache = HybridCacheBuilder::::new() + .memory(1) + .storage() + .build() + .await + .unwrap(); + + assert!(!cache.is_hybrid()); + } + #[test_log::test(tokio::test)] async fn test_hybrid_cache() { let dir = tempfile::tempdir().unwrap();