@@ -59,7 +59,7 @@ new sizeFun sizeLimit =
59
59
-- multiple threads try to access a key that doesn't exist in parallel, the
60
60
-- constructing action will be run only once.
61
61
--
62
- -- /Note:/ returned 'Bool' signifies whether the object was constructed .
62
+ -- /Note:/ returned 'Bool' signifies whether the object was in cache .
63
63
--
64
64
-- __Warning:__ for a given key, the constructing action needs to always return
65
65
-- the same result.
@@ -106,7 +106,7 @@ fetch (MemCache mv) key construct = do
106
106
)
107
107
108
108
case eel of
109
- Right el -> unlift $ pure (el, False )
109
+ Right el -> unlift $ pure (el, True )
110
110
Left (mvEl, mvAlreadyThere) -> do
111
111
-- If we got an existing MVar, wait for its result. Otherwise run
112
112
-- constructing action and update cache accordingly.
@@ -118,7 +118,7 @@ fetch (MemCache mv) key construct = do
118
118
-- If the thread that was supposed to construct the value
119
119
-- failed for some reason, let's try ourselves.
120
120
loop
121
- Just value -> unlift $ pure (value, False )
121
+ Just value -> unlift $ pure (value, True )
122
122
else do
123
123
evalue <- (`onException` removeInProgress mvEl) $ do
124
124
-- Construct the value and update cache accordingly.
@@ -132,7 +132,7 @@ fetch (MemCache mv) key construct = do
132
132
v <- liftBase . evaluate . force =<< construct
133
133
liftBase $ do
134
134
putMVar' mvEl $ Just v
135
- pure (v, True )
135
+ pure (v, False )
136
136
modifyMVar'_ mv $ \ mc ->
137
137
tryReadMVar' mvEl >>= \ case
138
138
Nothing -> do
@@ -172,7 +172,7 @@ fetch (MemCache mv) key construct = do
172
172
Just (_, _, minEl, tidiedCache) -> go tidiedCache $ size - mcSizeFun mc minEl
173
173
{-# INLINEABLE fetch #-}
174
174
175
- -- | Fetch an object from cache or construct it if it's not there .
175
+ -- | Variant of 'fetch' that doesn't return a 'Bool' .
176
176
fetch_
177
177
:: (Ord k , Hashable k , NFData v , MonadBaseControl IO m )
178
178
=> MemCache k v
0 commit comments