Esempio n. 1
0
        private async Task <IEnumerable <OpResponse> > GetModelsForIds(Type type, int freshnessSeconds, IEnumerable iids)
        {
            const int MaxParallelRequests = 10;
            var       ids = iids.Cast <object>();

            OpResponse[] allResponses = new OpResponse[ids.Count()];
            for (var i = 0; i < ids.Count(); i += MaxParallelRequests)
            {
                var someIds          = ids.Skip(i).Take(MaxParallelRequests);
                var someGetResponses = await Task.WhenAll(                      // wait on all requests in parallel
                    someIds.Select(id => ProcessRequest(                        // map each id to a get request and process it
                                       new RequestOp(
                                           NowMs,
                                           type,
                                           RequestVerb.Get,
                                           id,
                                           freshnessSeconds: freshnessSeconds
                                           )
                                       )
                                   )
                    );

                for (int j = 0; j < someGetResponses.Length; j++)                       // fill allResponses array from responses
                {
                    allResponses[i + j] = someGetResponses[j];
                }
            }
            return(allResponses.ToImmutableArray());
        }
Esempio n. 2
0
        private async Task StoreInPreviousCaches(OpResponse opResponse, ICascadeCache?layerFound = null)
        {
            var beforeLayer = layerFound == null;

            foreach (var layer in CacheLayers.Reverse())
            {
                if (!beforeLayer && layer == layerFound)
                {
                    beforeLayer = true;
                }
                if (!beforeLayer)
                {
                    continue;
                }
                await layer.Store(opResponse);
            }
        }