Esempio n. 1
0
        public async Task <TResponse> Get <TResponse>(object queryParams = null)
        {
            Url = GetFullUrl(queryParams);

            Log.For(this).Debug("Get: Url = " + Url);

            var urlLock = GetLocks.GetOrAdd(Url, x => new AsyncLock());

            using (await urlLock.Lock())
            {
                Exception firstError = null;
                // get result according to the cache policy
                foreach (var implementor in CachePolicy.GetImplementors <TResponse>(this))
                {
                    if (await implementor.Attempt(Url))
                    {
                        return(implementor.Result);
                    }

                    firstError = firstError ?? implementor.Error;
                }

                if (firstError != null)
                {
                    throw firstError;
                }
                else
                {
                    return(default(TResponse));
                }
            }
        }