public ActionResult CalculateDistance(string Source, string Destination) { var AirportData = _CacheRepository.Get <AirportDetails>(Constants.Constants.Airport); if (AirportData == null) { AirportDetails AirportDetailsObj = new AirportDetails(); AirportDetailsObj = _AirportDataRepository.GetAirportDetails(_ServiceHelperRepository); AirportData = AirportDetailsObj; _CacheRepository.Set <AirportDetails>(Constants.Constants.Airport, AirportDetailsObj); } var Distance = _GeoLocationRepository.GetDistance(AirportData, Source, Destination); return(Json(new { DistanceBetween = Math.Round(Distance, 2) })); }
private ExchangeService GetExchangeService(EmailCredentials credentials) { var url = credentials.AccessEndPoint; var cacheKey = BuildCacheKey(credentials.Email); if (string.IsNullOrWhiteSpace(url)) { url = _cacheRepository.Get <string>(cacheKey); } if (string.IsNullOrWhiteSpace(url)) { var autodiscover = new AutodiscoverService(ExchangeVersion.Exchange2013_SP1) { RedirectionUrlValidationCallback = x => true, Credentials = new WebCredentials(credentials.Email, credentials.Password) }; var userSettings = autodiscover.GetUsersSettings(new List <string>() { credentials.Email }, UserSettingName.ExternalEwsUrl); var successResponse = userSettings.First(x => x.ErrorCode == AutodiscoverErrorCode.NoError); successResponse.TryGetSettingValue(UserSettingName.ExternalEwsUrl, out url); _cacheRepository.Put(cacheKey, url, new CacheRepositoryOptions()); } var service = new ExchangeService(ExchangeVersion.Exchange2013_SP1) { Credentials = new WebCredentials(credentials.Email, credentials.Password), Url = new Uri(url) }; return(service); }
public async Task <AttemptsDB_AttemptDTO> GetActiveAttemptByMemberId(ObjectId memberId) { AttemptsDB_AttemptDTO attempt; if (!_internalActiveByMemberIdCache.ContainsKey(memberId) || _internalActiveByMemberIdCache[memberId] != null && !_internalByIdCache.ContainsKey(_internalActiveByMemberIdCache[memberId].Value)) { attempt = await _redisCache.Get($"MemberActiveAttempt:{memberId}", async() => await AttemptWorker.GetActiveAttemptByMemberId(memberId)); if (attempt != null) { _internalActiveByMemberIdCache.TryAdd(memberId, attempt.Id); _internalByIdCache.TryAdd(attempt.Id, attempt); } else { _internalActiveByMemberIdCache.TryAdd(memberId, null); } } else { attempt = _internalActiveByMemberIdCache[memberId] != null ? _internalByIdCache[_internalActiveByMemberIdCache[memberId].Value] : null; } return(attempt); }
public ViewResult StackExchange([Bind(Prefix = "id")] int pageNumber = 1) { var cache = caches.Get(); var paged = answers.Page(cache, pageNumber - 1, 10); return(View(paged)); }
public Token Login(Login login) { if (login.GrantType == "password") { var user = new User { UserName = login.UserId, PasswordHash = login.Password }; var verify = _userService.Verify(user); if (verify) { return(Token(login)); } } else if (login.GrantType == "refresh_token") { var refreshToken = _cacheRepository.Get(login.RefreshToken); if (refreshToken != null) { return(Token(login)); } } return(null); }
/// <summary> /// Get the object from the Cache /// </summary> /// <param name="key"/> /// <returns/> public object Get(object key) { if (key == null) { return(null); } return(Repository.Get(GetCacheId(key))); }
public async Task <object> GetAsync(RequestModel requestModel) { if (requestModel.Type == RequestType.GET) { return(_cacheRepository.Get(requestModel.Key)); } return("Not valid request type"); }
/// <summary> /// Gets the cart using specified user identifier. /// </summary> /// <param name="userId">The user identifier.</param> /// <returns></returns> public async Task <CartDetailedResponseDto> Get(int userId) { List <CartResponseDto> carts = await _repository.Get(userId); CartDetailedResponseDto responseDto = new CartDetailedResponseDto { cartItems = carts, Total = carts.Aggregate(0, (seed, item) => item.Cost + seed) }; await _cacheRepository.Get(userId.ToString(), responseDto); return(responseDto); }
public static T ReturnFromCache <T>(ICacheRepository cacheRepository, string name, int ttl, Func <T> action) where T : class { var item = cacheRepository.Get(name) as T; if (item == null) { item = action(); cacheRepository.Put(name, item, ttl); } return(item); }
public GenericResponse <bool> SaveABet(Bet bet) { return(CatchErrorHelper.Try(() => { var roulette = CacheRepository.Get <Roulette>(bet.RouletteId); roulette.Bets ??= new List <Bet>(); roulette.Bets.Add(bet); BetService.IsValidBet(bet); BetService.IsValidRoulette(roulette); BetService.AssignPrize(bet); CacheRepository.Save(roulette.Id, roulette); return true; })); }
public EShopRepository(ICacheRepository cacheProvider, Common.Enums.Connections connection) : base(connection) { _cacheRepository = cacheProvider; if (!_cacheRepository.IsSet("cache_eshopschema")) { _eShopDataAdapter = new DbSqlAdapter("EShop.Data.Queries.EShopSchema.xml"); _cacheRepository.Set("cache_eshopschema", _eShopDataAdapter); } else { _eShopDataAdapter = _cacheRepository.Get <DbSqlAdapter>("cache_eshopschema"); } }
public void GetValue_ExistingInCache_ReturnValue() { var keyValue = "value"; var configurationReader = new ConfigurationEngine(_dataRepository, _mockCacheRepository, ApplicationName, 1); _mockCacheRepository.Get <List <CacheConfigurationDTO> >(Arg.Any <string>()).Returns( new List <CacheConfigurationDTO> { new CacheConfigurationDTO { Name = "name", ApplicationName = ApplicationName, Value = keyValue, Type = "String", IsActive = true } }); var result = configurationReader.GetValue <string>("name"); Assert.AreEqual(result, keyValue); }
public async Task <Response <List <string> > > TopTags() { var response = new Response <List <string> >(); try { var result = await _mongoRepository.GetTags <Post>(); var tops = result.OrderByDescending(o => o.value).Take(50).Select(s => s.Id).ToList(); if (!_cacheRepository.Exists("kb_tags") || _cacheRepository.Get("kb_tags") == null) { _cacheRepository.Set("kb_tags", tops, new TimeSpan(4, 0, 0)); } response.Data = _cacheRepository.Get <List <string> >("kb_tags"); } catch (Exception ex) { response.Status = 0; response.Msg = ex.Message.ToString(); } return(response); }
public async Task <RoomsDB_RoomDTO> GetRoomById(ObjectId roomId) { RoomsDB_RoomDTO room; if (_internalByIdCache.ContainsKey(roomId)) { room = _internalByIdCache[roomId]; } else { room = await _redisCache.Get($"Room:{roomId}", async() => await RoomWorker.GetRoomById(roomId)); _internalByIdCache.Add(roomId, room); } return(room); }
private async Task <IHttpActionResult> ProcessGetRequest <T>() { // Extract the request URL. string path = Request.RequestUri.PathAndQuery; // Try to find the cached response. T cachedData = _cacheRepository.Get <T>(path); // Send cached response. if (cachedData != null) { // === Return data. return(Ok(cachedData)); } // Choose DataWarehouse server. int dateWarehousePort = _dataWarehousesPorts.Next(); // Make request to the Data Warehouse. HttpResponseMessage response = null; using (HttpClient httpClient = new HttpClient()) { // Set the base address and the Accept header. httpClient.BaseAddress = new Uri($"http://localhost:" + dateWarehousePort + "/"); httpClient.DefaultRequestHeaders.Clear(); httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); // Make request to the DataWarehouse. response = await httpClient.GetAsync(path.Substring(1)); } if (response.IsSuccessStatusCode) { // Cache the response. T data = await CacheResponseBody <T>(response, path); // Return data. return(Ok(data)); } return(InternalServerError()); }
public T Get <T>(string cacheKey, Func <T> fallbackFunction, TimeSpan timeSpan, bool useCache = true) where T : class { if (_cacheRepository == null || !useCache) { return(fallbackFunction()); } var data = _cacheRepository.Get(cacheKey); if (data != null) { if (data == DBNull.Value) { return(null); } return(data as T); } var data2 = fallbackFunction(); _cacheRepository.Add(cacheKey, data2 ?? (object)DBNull.Value, timeSpan); return(data2); }
public async Task <T> Get <T>(Guid id, int?expectedVersion = null) where T : AggregateRoot { if (IsTracked(id)) { var trackedAggregate = (T)_trackedAggregates[id].Aggregate; if (expectedVersion != null && trackedAggregate.Version != expectedVersion) { throw new ConcurrencyException(trackedAggregate.Id); } return(trackedAggregate); } var aggregate = await _repository.Get <T>(id); if (expectedVersion != null && aggregate.Version != expectedVersion) { throw new ConcurrencyException(id); } await Add(aggregate); return(aggregate); }
public async Task <MembersDB_MemberDTO> GetMemberById(ObjectId memberId) => await _redisCache.Get <MembersDB_MemberDTO>($"Member:{memberId}", async() => await MemberWorker.GetMemberById(memberId));
public async Task <T> Get <T>(string key) { return(await _cacheRepository.Get <T>(key)); }
public TEntity Get(string key) { return(_repository.Get(key)); }
/// <summary> /// Get by type. /// Cache key is automagically created from object type and identify. /// Example: repo.GetByType{User}(1); // Get User 1 /// </summary> /// <typeparam name="T">Type of cached object</typeparam> /// <param name="repo">ICacheRepository</param> /// <param name="identifier">Type specific unique identify for object</param> /// <returns>Cached object, null if no record found</returns> public static T GetByType <T>(this ICacheRepository repo, object identifier) { var key = AsyncCacheRepositoryExtensions.CreateKey <T>(identifier); return(repo.Get <T>(key)); }
public async Task <UsersDB_UserDTO> GetUserById(ObjectId userId) => await _redisCache.Get($"User:{userId}", async() => await UserWorker.GetUserById(userId));
public T Get <T>(string cacheKey) where T : class { return(cacheRepository.Get <T>(cacheKey)); }
public string GetValue(string key) { return(Exists(key) ? SanitizedString(_cacheRepo.Get(key).Value) : null); }
public Bet GetABet(Guid id) { return(CacheRepository.Get <Entities.Bet>(id)); }
/// <summary> /// 비동기 방식으로 캐시에 저장된 항목을 로드합니다. /// </summary> /// <param name="repository"></param> /// <param name="key"></param> /// <returns></returns> public static Task <object> GetAsync(this ICacheRepository repository, string key) { key.ShouldNotBeWhiteSpace("key"); return(Task.Factory.StartNew(() => repository.Get(key))); }