@@ -166,7 +166,7 @@ public static IObservable<T> GetAndFetchLatestFromIndex<T>(
166
166
this IBlobCache blobCache ,
167
167
string key ,
168
168
Func < IObservable < T > > fetchFunc ,
169
- Action < string > removedItemsCallback ,
169
+ Action < T > removedItemsCallback ,
170
170
TimeSpan refreshInterval ,
171
171
TimeSpan maxCacheDuration )
172
172
where T : CacheItem
@@ -194,35 +194,31 @@ public static IObservable<T> GetAndFetchLatestFromIndex<T>(
194
194
static IObservable < T > GetAndFetchLatestFromIndex < T > ( this IBlobCache This ,
195
195
string key ,
196
196
Func < IObservable < T > > fetchFunc ,
197
- Action < string > removedItemsCallback ,
197
+ Action < T > removedItemsCallback ,
198
198
Func < DateTimeOffset , bool > fetchPredicate = null ,
199
199
DateTimeOffset ? absoluteExpiration = null ,
200
200
bool shouldInvalidateOnError = false )
201
201
where T : CacheItem
202
202
{
203
203
var idx = Observable . Defer ( ( ) => This . GetOrCreateObject ( key , ( ) => CacheIndex . Create ( key ) ) ) . Replay ( ) . RefCount ( ) ;
204
-
204
+
205
205
206
206
var fetch = idx
207
207
. Select ( x => Tuple . Create ( x , fetchPredicate == null || ! x . Keys . Any ( ) || fetchPredicate ( x . UpdatedAt ) ) )
208
208
. Where ( predicateIsTrue => predicateIsTrue . Item2 )
209
209
. Select ( x => x . Item1 )
210
210
. Select ( index => index . Clear ( ) )
211
- . SelectMany ( index =>
212
- {
213
- var fetchObs = fetchFunc ( )
211
+ . SelectMany ( index => fetchFunc ( )
214
212
. Catch < T , Exception > ( ex =>
215
213
{
216
214
var shouldInvalidate = shouldInvalidateOnError ?
217
215
This . InvalidateObject < CacheIndex > ( key ) :
218
216
Observable . Return ( Unit . Default ) ;
219
217
return shouldInvalidate . SelectMany ( __ => Observable . Throw < T > ( ex ) ) ;
220
- } ) ;
221
-
222
- return fetchObs
218
+ } )
223
219
. SelectMany ( x => x . Save < T > ( This , key , absoluteExpiration ) )
224
- . Do ( x => index . Add ( key , x ) ) ;
225
- } ) ;
220
+ . Do ( x => index . Add ( key , x ) )
221
+ ) ;
226
222
227
223
var cache = idx
228
224
. SelectMany ( index => This . GetObjects < T > ( index . Keys . ToList ( ) ) )
@@ -237,7 +233,8 @@ static IObservable<T> GetAndFetchLatestFromIndex<T>(this IBlobCache This,
237
233
var list = index . OldKeys . Except ( index . Keys ) ;
238
234
if ( ! list . Any ( ) )
239
235
return ;
240
- foreach ( var d in list )
236
+ var removed = await This . GetObjects < T > ( list ) ;
237
+ foreach ( var d in removed . Values )
241
238
removedItemsCallback ( d ) ;
242
239
await This . InvalidateObjects < T > ( list ) ;
243
240
} )
0 commit comments