@@ -42,10 +42,12 @@ use foyer_memory::{Cache, CacheEntry, Fetch, FetchContext, FetchState, Piece, Pi
4242use foyer_storage:: { IoThrottler , Load , Statistics , Store } ;
4343use pin_project:: pin_project;
4444use serde:: { Deserialize , Serialize } ;
45- use tokio:: sync:: oneshot;
4645
47- use super :: writer:: HybridCacheStorageWriter ;
48- use crate :: { HybridCacheBuilder , HybridCacheWriter } ;
46+ use crate :: hybrid:: {
47+ builder:: HybridCacheBuilder ,
48+ error:: { Error , Result } ,
49+ writer:: { HybridCacheStorageWriter , HybridCacheWriter } ,
50+ } ;
4951
5052#[ cfg( feature = "tracing" ) ]
5153macro_rules! root_span {
@@ -316,7 +318,7 @@ where
316318 memory : Cache < K , V , S , HybridCacheProperties > ,
317319 storage : Store < K , V , S , HybridCacheProperties > ,
318320 flush_on_close : bool ,
319- ) -> anyhow :: Result < ( ) > {
321+ ) -> Result < ( ) > {
320322 if closed. fetch_or ( true , Ordering :: Relaxed ) {
321323 return Ok ( ( ) ) ;
322324 }
@@ -333,7 +335,7 @@ where
333335 Ok ( ( ) )
334336 }
335337
336- async fn close ( & self ) -> anyhow :: Result < ( ) > {
338+ async fn close ( & self ) -> Result < ( ) > {
337339 Self :: close_inner (
338340 self . closed . clone ( ) ,
339341 self . memory . clone ( ) ,
@@ -571,7 +573,7 @@ where
571573 }
572574
573575 /// Get cached entry with the given key from the hybrid cache.
574- pub async fn get < Q > ( & self , key : & Q ) -> anyhow :: Result < Option < HybridCacheEntry < K , V , S > > >
576+ pub async fn get < Q > ( & self , key : & Q ) -> Result < Option < HybridCacheEntry < K , V , S > > >
575577 where
576578 Q : Hash + Equivalent < K > + Send + Sync + ' static + Clone ,
577579 {
@@ -650,7 +652,7 @@ where
650652 ///
651653 /// `obtain` is always supposed to be used instead of `get` if the overhead of getting the ownership of the given
652654 /// key is acceptable.
653- pub async fn obtain ( & self , key : K ) -> anyhow :: Result < Option < HybridCacheEntry < K , V , S > > >
655+ pub async fn obtain ( & self , key : K ) -> Result < Option < HybridCacheEntry < K , V , S > > >
654656 where
655657 K : Clone ,
656658 {
@@ -667,7 +669,7 @@ where
667669 || {
668670 let store = self . inner . storage . clone ( ) ;
669671 async move {
670- match store. load ( & key) . await . map_err ( anyhow :: Error :: from) {
672+ match store. load ( & key) . await . map_err ( Error :: from) {
671673 Ok ( Load :: Entry {
672674 key : _,
673675 value,
@@ -681,7 +683,7 @@ where
681683 } ,
682684 Ok ( Load :: Throttled ) => Err ( ObtainFetchError :: Throttled ) . into ( ) ,
683685 Ok ( Load :: Miss ) => Err ( ObtainFetchError :: NotExist ) . into ( ) ,
684- Err ( e) => Err ( ObtainFetchError :: Err ( e) ) . into ( ) ,
686+ Err ( e) => Err ( ObtainFetchError :: Other ( e) ) . into ( ) ,
685687 }
686688 }
687689 } ,
@@ -720,11 +722,7 @@ where
720722 try_cancel ! ( self , span, record_hybrid_obtain_threshold) ;
721723 Ok ( None )
722724 }
723- Err ( ObtainFetchError :: RecvError ( _) ) => {
724- try_cancel ! ( self , span, record_hybrid_obtain_threshold) ;
725- Ok ( None )
726- }
727- Err ( ObtainFetchError :: Err ( e) ) => {
725+ Err ( ObtainFetchError :: Other ( e) ) => {
728726 try_cancel ! ( self , span, record_hybrid_obtain_threshold) ;
729727 Err ( e)
730728 }
@@ -766,7 +764,7 @@ where
766764 }
767765
768766 /// Clear the hybrid cache.
769- pub async fn clear ( & self ) -> anyhow :: Result < ( ) > {
767+ pub async fn clear ( & self ) -> Result < ( ) > {
770768 self . inner . memory . clear ( ) ;
771769 self . inner . storage . destroy ( ) . await ?;
772770 Ok ( ( ) )
@@ -781,7 +779,7 @@ where
781779 /// For more details, please refer to [`super::builder::HybridCacheBuilder::with_flush_on_close()`].
782780 ///
783781 /// If `close` is not called explicitly, the hybrid cache will be closed when its last copy is dropped.
784- pub async fn close ( & self ) -> anyhow :: Result < ( ) > {
782+ pub async fn close ( & self ) -> Result < ( ) > {
785783 self . inner . close ( ) . await
786784 }
787785
@@ -819,13 +817,12 @@ where
819817enum ObtainFetchError {
820818 Throttled ,
821819 NotExist ,
822- RecvError ( oneshot:: error:: RecvError ) ,
823- Err ( anyhow:: Error ) ,
820+ Other ( Error ) ,
824821}
825822
826- impl From < oneshot :: error :: RecvError > for ObtainFetchError {
827- fn from ( e : oneshot :: error :: RecvError ) -> Self {
828- Self :: RecvError ( e )
823+ impl From < foyer_memory :: Error > for ObtainFetchError {
824+ fn from ( e : foyer_memory :: Error ) -> Self {
825+ Self :: Other ( e . into ( ) )
829826 }
830827}
831828
@@ -846,7 +843,7 @@ where
846843 S : HashBuilder + Debug ,
847844{
848845 #[ pin]
849- inner : Fetch < K , V , anyhow :: Error , S , HybridCacheProperties > ,
846+ inner : Fetch < K , V , Error , S , HybridCacheProperties > ,
850847 policy : HybridCachePolicy ,
851848 storage : Store < K , V , S , HybridCacheProperties > ,
852849}
@@ -857,7 +854,7 @@ where
857854 V : StorageValue ,
858855 S : HashBuilder + Debug ,
859856{
860- type Output = anyhow :: Result < CacheEntry < K , V , S , HybridCacheProperties > > ;
857+ type Output = Result < CacheEntry < K , V , S , HybridCacheProperties > > ;
861858
862859 fn poll ( self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < Self :: Output > {
863860 let mut this = self . project ( ) ;
@@ -885,7 +882,7 @@ where
885882 V : StorageValue ,
886883 S : HashBuilder + Debug ,
887884{
888- type Target = Fetch < K , V , anyhow :: Error , S , HybridCacheProperties > ;
885+ type Target = Fetch < K , V , Error , S , HybridCacheProperties > ;
889886
890887 fn deref ( & self ) -> & Self :: Target {
891888 & self . inner
@@ -905,7 +902,7 @@ where
905902 pub fn fetch < F , FU > ( & self , key : K , fetch : F ) -> HybridFetch < K , V , S >
906903 where
907904 F : FnOnce ( ) -> FU ,
908- FU : Future < Output = anyhow :: Result < V > > + Send + ' static ,
905+ FU : Future < Output = Result < V > > + Send + ' static ,
909906 {
910907 self . fetch_inner ( key, HybridCacheProperties :: default ( ) , fetch)
911908 }
@@ -922,15 +919,15 @@ where
922919 ) -> HybridFetch < K , V , S >
923920 where
924921 F : FnOnce ( ) -> FU ,
925- FU : Future < Output = anyhow :: Result < V > > + Send + ' static ,
922+ FU : Future < Output = Result < V > > + Send + ' static ,
926923 {
927924 self . fetch_inner ( key, properties, fetch)
928925 }
929926
930927 fn fetch_inner < F , FU > ( & self , key : K , properties : HybridCacheProperties , fetch : F ) -> HybridFetch < K , V , S >
931928 where
932929 F : FnOnce ( ) -> FU ,
933- FU : Future < Output = anyhow :: Result < V > > + Send + ' static ,
930+ FU : Future < Output = Result < V > > + Send + ' static ,
934931 {
935932 root_span ! ( self , span, "foyer::hybrid::cache::fetch" ) ;
936933
@@ -950,7 +947,7 @@ where
950947 let runtime = self . storage ( ) . runtime ( ) . clone ( ) ;
951948
952949 async move {
953- let throttled = match store. load ( & key) . await . map_err ( anyhow :: Error :: from) {
950+ let throttled = match store. load ( & key) . await . map_err ( Error :: from) {
954951 Ok ( Load :: Entry {
955952 key : _,
956953 value,
0 commit comments