private async Task PollAlgorithm(AlgorithmId algorithmId, ResultSubscriptionType subscription)
        {
            if (subscription == 0)
            {
                throw new ArgumentOutOfRangeException(nameof(subscription), "No data has been subscribed");
            }

            var result = await _cache.GetOrCreateObject(algorithmId.DeployId, () => new AlgorithmResult
            {
                AlgorithmId = algorithmId,
            });

            // Check whether we need to update live results
            if ((subscription & ResultSubscriptionType.LiveResults) != 0)
            {
                try
                {
                    var remoteLiveAlgorithmResults = await _apiService.Api.GetLiveAlgorithmResultsAsync(algorithmId.ProjectId, algorithmId.DeployId);

                    _apiResultParser.ProcessLiveResult(result, remoteLiveAlgorithmResults);
                }
                catch (Exception ex)
                {
                    // TODO: Log
                }
            }

            // Check whether we need to update the log
            if ((subscription & ResultSubscriptionType.Log) != 0)
            {
                try
                {
                    // var logResults = await _apiService.Api.GetLiveAlgorithmLogs(algorithmId.ProjectId, algorithmId.DeployId);
                    // _apiResultParser.ProcessLogResult(result, logResults);
                }
                catch
                {
                    // TODO: Log
                }
            }

            // Fire the result event
            OnAlgorithmResultUpdated(new AlgorithmResultEventArgs(result));

            // Cache the result
            await _cache.InsertObject(algorithmId.DeployId, result);
        }
        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);
            }
        }