public static async Task InsertIfMoreDetailsAsync <T>(this IObjectBlobCache cache,
                                                       IDictionary <string, T> keyValuePairs, DateTimeOffset expiration) where T : class, IDetailLeveled
 {
     foreach (var pair in keyValuePairs)
     {
         await InsertIfMoreDetailsAsync(cache, pair.Key, pair.Value, expiration).ConfigureAwait(false);
     }
 }
Пример #2
0
        public AlgorithmService(IAlgorithmRepository algorithmRepository, IAlgorithmResultProvider algorithmResultProvider, IObjectBlobCache cache)
        {
            _algorithmRepository     = algorithmRepository;
            _algorithmResultProvider = algorithmResultProvider;
            _cache = cache;

            _algorithmResultProvider.Run();

            CreateResultObservable();
        }
        public static async Task InsertWithoutOverwriteAsync <T>(this IObjectBlobCache cache, string key, T value,
                                                                 DateTimeOffset expiration) where T : class
        {
            await cache.Flush();

            T fromCache;

            try
            {
                fromCache = await cache.GetObject <T>(key);
            }
            catch (KeyNotFoundException)
            {
                fromCache = null;
            }
            if (fromCache != null)
            {
                await cache.InsertObject(key, value, expiration);
            }
        }
        public static async Task InsertIfMoreDetailsAsync <T>(this IObjectBlobCache cache, string key, T value,
                                                              DateTimeOffset expiration) where T : class, IDetailLeveled
        {
            await cache.Flush();

            IDetailLeveled fromCache;

            try
            {
                fromCache = await cache.GetObject <T>(key);
            }
            catch (KeyNotFoundException)
            {
                fromCache = null;
            }
            var newValue = (IDetailLeveled)value;

            if (fromCache == null || newValue.GetDetailLevel() >= fromCache.GetDetailLevel())
            {
                await cache.InsertObject(key, value, expiration);
            }
        }
        public static async Task InsertAllIfMoreDetailsAsync <T>(this IObjectBlobCache cache,
                                                                 IDictionary <string, T> keyValuePairs, DateTimeOffset expiration) where T : class, IDetailLeveled
        {
            await cache.Flush();

            var toInsert = new Dictionary <string, T>();

            foreach (var pair in keyValuePairs)
            {
                IDetailLeveled fromCache;
                try
                {
                    fromCache = await cache.GetObject <T>(pair.Key);
                }
                catch (KeyNotFoundException)
                {
                    fromCache = null;
                }
                var newValue = (IDetailLeveled)pair.Value;
                if (fromCache == null || newValue.GetDetailLevel() >= fromCache.GetDetailLevel())
                {
                    toInsert.Add(pair.Key, pair.Value);
                }
            }
            if (toInsert.Any())
            {
                try
                {
                    await cache.InsertObjects(toInsert, expiration);
                }
                catch (Exception e)
                {
                    ServiceLocator.Current.GetInstance <ILoggingService>().Report(e, cache);
                }
            }
        }
 public BlockingDisposeObjectCache(IObjectBlobCache cache) : base(cache)
 {
 }
 public static Task InsertIfMoreDetailsAsync <T>(this IObjectBlobCache cache, IDictionary <string, T> keyValuePairs,
                                                 TimeSpan expiration) where T : class, IDetailLeveled
 => InsertIfMoreDetailsAsync(cache, keyValuePairs, DateTimeOffset.UtcNow + expiration);
 public static Task InsertIfMoreDetailsAsync <T>(this IObjectBlobCache cache, string key, T value,
                                                 TimeSpan expiration)
     where T : class, IDetailLeveled
 => InsertIfMoreDetailsAsync(cache, key, value, DateTimeOffset.UtcNow + expiration);
 public static Task InsertWithoutOverwriteAsync <T>(this IObjectBlobCache cache,
                                                    IDictionary <string, T> keyValuePairs,
                                                    TimeSpan expiration) where T : class
 => InsertWithoutOverwriteAsync(cache, keyValuePairs, DateTimeOffset.UtcNow + expiration);
 public static Task InsertWithoutOverwriteAsync <T>(this IObjectBlobCache cache, string key, T value,
                                                    TimeSpan expiration) where T : class
 => InsertWithoutOverwriteAsync(cache, key, value, DateTimeOffset.UtcNow + expiration);
 public AlgorithmResultProvider(IApiService apiService, ISettingsService settingsService, IObjectBlobCache cache)
 {
     _apiService      = apiService;
     _settingsService = settingsService;
     _cache           = cache;
 }