public Task Logout() => Task.Run(async() => { var keys = await _blobCache.GetAllKeys(); foreach (var driveKey in keys.Where(x => x.StartsWith("google-drive", StringComparison.OrdinalIgnoreCase))) { await _blobCache.Invalidate(driveKey); } _driveService = null; _isAuthorized.OnNext(false); return(Task.CompletedTask); });
public IObservable <IEnumerable <GitHubPullRequest> > GetPullRequests() { var key = $"{nameof(GitHubPullRequest)}.{_currentRepository.Id}"; return(_blob.GetAllKeys() .Select(keys => { if (keys.Contains(key)) { return _blob.GetObject <IEnumerable <GitHubPullRequest> >(key).Wait(); } _blob.InsertObject(key, new List <GitHubPullRequest>()); return Observable.Return(new List <GitHubPullRequest>()).Wait(); })); }
/// <summary> /// Invalidates all objects of the specified type. To invalidate all /// objects regardless of type, use InvalidateAll. /// </summary> /// <typeparam name="T">The type of item to invalidate.</typeparam> /// <param name="blobCache">The cache to invalidate.</param> /// <returns>An observable that signals when the operation has finished.</returns> /// <remarks>Returns a Unit for each invalidation completion. Use Wait instead of First to wait for /// this.</remarks> public static IObservable <Unit> InvalidateAllObjects <T>(this IBlobCache blobCache) { if (blobCache is null) { throw new ArgumentNullException(nameof(blobCache)); } if (blobCache is IObjectBlobCache objCache) { return(objCache.InvalidateAllObjects <T>()); } var ret = new AsyncSubject <Unit>(); blobCache.GetAllKeys() .SelectMany(x => x.Where(y => y.StartsWith(GetTypePrefixedKey(string.Empty, typeof(T)), StringComparison.InvariantCulture)) .ToObservable()) .SelectMany(blobCache.Invalidate) .Subscribe( _ => { }, ex => ret.OnError(ex), () => { ret.OnNext(Unit.Default); ret.OnCompleted(); }); return(ret); }
public static void InvalidateAllObjects <T>(this IBlobCache This) { foreach (var key in This.GetAllKeys().Where(x => x.StartsWith(GetTypePrefixedKey("", typeof(T))))) { This.Invalidate(key); } }
/// <summary> /// Return all objects of a specific Type in the cache. /// </summary> /// <returns>A Future result representing all objects in the cache /// with the specified Type.</returns> public static IObservable <IEnumerable <T> > GetAllObjects <T>(this IBlobCache This) { // NB: This isn't exactly thread-safe, but it's Close Enough(tm) // We make up for the fact that the keys could get kicked out // from under us via the Catch below var matchingKeys = This.GetAllKeys() .Where(x => x.StartsWith(GetTypePrefixedKey("", typeof(T)))) .ToArray(); return(matchingKeys.ToObservable() .SelectMany(x => This.GetObjectAsync <T>(x, true).Catch(Observable.Empty <T>())) .ToList() .Select(x => (IEnumerable <T>)x)); }
public CacheService() { BlobCache.ApplicationName = KeyValues.AppName; BlobCache.EnsureInitialized(); BlobCache.ForcedDateTimeKind = DateTimeKind.Utc; _blob = BlobCache.LocalMachine; _apiService = Locator.Current.GetService <IApiService>(); _blob.GetAllKeys().Subscribe(keys => { if (keys is null || !keys.Any()) { _blob.InsertObject(nameof(GitHubRepository), new List <GitHubRepository>()); } }); }
/// <summary> /// Return all objects of a specific Type in the cache. /// </summary> /// <param name="blobCache">The cache to get the items.</param> /// <typeparam name="T">The type of item to get.</typeparam> /// <returns>A Future result representing all objects in the cache /// with the specified Type.</returns> public static IObservable <IEnumerable <T> > GetAllObjects <T>(this IBlobCache blobCache) { if (blobCache is IObjectBlobCache objCache) { return(objCache.GetAllObjects <T>()); } // NB: This isn't exactly thread-safe, but it's Close Enough(tm) // We make up for the fact that the keys could get kicked out // from under us via the Catch below return(blobCache.GetAllKeys() .SelectMany(x => x .Where(y => y.StartsWith(GetTypePrefixedKey(string.Empty, typeof(T)), StringComparison.InvariantCulture)) .ToObservable()) .SelectMany(x => blobCache.GetObject <T>(x) .Catch(Observable.Empty <T>())) .ToList()); }
/// <summary> /// Invalidates all objects of the specified type. To invalidate all /// objects regardless of type, use InvalidateAll. /// </summary> /// <remarks>Returns a Unit for each invalidation completion. Use Wait instead of First to wait for /// this.</remarks> public static IObservable <Unit> InvalidateAllObjects <T>(this IBlobCache This) { var objCache = This as IObjectBlobCache; if (objCache != null) { return(objCache.InvalidateAllObjects <T>()); } var ret = new AsyncSubject <Unit>(); This.GetAllKeys().Where(x => x.StartsWith(GetTypePrefixedKey("", typeof(T)))) .ToObservable() .SelectMany(This.Invalidate) .Subscribe( _ => { }, ex => ret.OnError(ex), () => { ret.OnNext(Unit.Default); ret.OnCompleted(); }); return(ret); }
/// <summary> /// Return all objects of a specific Type in the cache. /// </summary> /// <returns>A Future result representing all objects in the cache /// with the specified Type.</returns> public static IObservable <IEnumerable <T> > GetAllObjects <T>(this IBlobCache This) { var objCache = This as IObjectBlobCache; if (objCache != null) { return(objCache.GetAllObjects <T>()); } // NB: This isn't exactly thread-safe, but it's Close Enough(tm) // We make up for the fact that the keys could get kicked out // from under us via the Catch below return(This.GetAllKeys() .SelectMany(x => x .Where(y => y.StartsWith(GetTypePrefixedKey("", typeof(T)))) .ToObservable()) .SelectMany(x => This.GetObject <T>(x) .Catch(Observable.Empty <T>())) .ToList()); }
/// <summary> /// Return all objects of a specific Type in the cache. /// </summary> /// <returns>A Future result representing all objects in the cache /// with the specified Type.</returns> public static IObservable <IEnumerable <T> > GetAllObjects <T>(this IBlobCache This) { var objCache = This as IObjectBlobCache; if (objCache != null) { return(objCache.GetAllObjects <T>()); } // NB: This isn't exactly thread-safe, but it's Close Enough(tm) // We make up for the fact that the keys could get kicked out // from under us via the Catch below var matchingKeys = This.GetAllKeys() .ToArray(); return(matchingKeys.ToObservable() .SelectMany(x => This.GetObjectAsync <T>(x, true).Catch(Observable.Empty <T>())) .ToList() .Where(x => x is T) .Select(x => (IEnumerable <T>)x)); }
public IObservable <IEnumerable <string> > GetAllKeys() { return(_inner.GetAllKeys()); }
public static async Task <IEnumerable <Destination> > GetDestinations() { var x = await Cache.GetAllKeys(); return(await Cache.GetAllObjects <Destination>()); }
public IEnumerable <string> GetAllKeys() { return(_inner.GetAllKeys()); }