Exemplo n.º 1
0
        public void Handle_concurrent_access()
        {
            // Arrange
            const string testKey        = "key";
            const string result         = "Ok";
            var          timesRetrieved = 0;

            Task <string> RetrievalFuncAsync()
            {
                timesRetrieved++;
                Thread.Sleep(2);
                return(Task.FromResult(result));
            }

            // Act
            var task1 = Task.Run(() => Cacher.GetAsync(testKey, (Func <Task <string> >)RetrievalFuncAsync));
            var task2 = Task.Run(() => Cacher.GetAsync(testKey, (Func <Task <string> >)RetrievalFuncAsync));

            Task.WaitAll(task1, task2);

            //Assert
            task1.Result.Should().Be(result);
            task2.Result.Should().Be(result);
            timesRetrieved.Should()
            .Be(1, "Retrival function should be called only the first time. Second time should be retrieved from cache");
        }
Exemplo n.º 2
0
        public async Task <IEnumerable <Institution> > InstitutionsAsync()
        {
            var insitutions = await Cacher
                              .GetAsync(BankStatementsUtil.BankStatementsInstitutionsList, GetInstitutionPayloadAsync)
                              .ConfigureAwait(false);

            return(insitutions);
        }
Exemplo n.º 3
0
        private async Task Init()
        {
            //  _companyCache = await Cacher.GetOrSetAsync<IEnumerable<Company>>("companies", () => Task.FromResult(_companies.GetAll()));
            if (!UseCache)
            {
                LocalityCache   = Localities.GetAll();
                ClassifierCache = Classifiers.GetAll();
            }
            else
            {
                LocalityCache =
                    await Cacher.GetAsync("localities", () => Task.FromResult(Localities.GetAll()));

                ClassifierCache =
                    await Cacher.GetAsync("classifiers",
                                          () => Task.FromResult(Classifiers.GetAll()));
            }
        }