예제 #1
0
파일: CacherShould.cs 프로젝트: lulzzz/vita
        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");
        }
예제 #2
0
        public async Task <IEnumerable <Institution> > InstitutionsAsync()
        {
            var insitutions = await Cacher
                              .GetAsync(BankStatementsUtil.BankStatementsInstitutionsList, GetInstitutionPayloadAsync)
                              .ConfigureAwait(false);

            return(insitutions);
        }
예제 #3
0
파일: MatchBase.cs 프로젝트: lulzzz/vita
        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()));
            }
        }