protected T Get <T>(string key, string region) { if (string.IsNullOrEmpty(region)) { return(appFabricCache.Get <T>(key)); } //This function will create if region doesnt exists. Prevents exception if called before adding elements into Region appFabricCache.CreateRegion(region); return(appFabricCache.Get <T>(key, region)); }
public List <UserSalesModel> GetSales(DateTime?fromDate, DateTime?toDate) { List <UserSalesModel> userSales = _userSalesCache.Get <List <UserSalesModel> >(DataCacheKey.UserSales); if (fromDate != null) { userSales = userSales.Where(s => s.Last_Purchase_Date >= fromDate).ToList(); } if (toDate != null) { userSales = userSales.Where(s => s.Last_Purchase_Date <= toDate).ToList(); } return(userSales); }
public async Task <bool> IsTileKnownToBeMissing(string tileDetail) { var cacheKey = GetCacheKey(tileDetail); using (await MemCacheLock.LockAsync(cacheKey)) return(!string.IsNullOrEmpty(_dataCache.Get <string>(cacheKey))); }
public Task <bool> IsDownloadedAsync(int tenantId, string localDirectory, string report) { var cacheKey = string.Format(CacheKeyFormat, tenantId); var reports = _cache.Get(cacheKey); if (reports?.Length > 0 && reports.Contains(report)) { return(Task.FromResult(true)); } if (!Directory.Exists(localDirectory)) { return(Task.FromResult(false)); } reports = Directory.GetFiles(localDirectory); var isDownload = false; foreach (var downloadReport in reports) { isDownload = downloadReport.Contains(report); if (!isDownload) { continue; } _cache.TryAdd(cacheKey, reports); } return(Task.FromResult(isDownload)); }
public IActionResult GetItem(string key) { var obj = cache.Get <object>(key); if (obj == null) { return(Json(null)); } var result = new { Data = obj, Tags = cache.GetTagsForKey(key) }; return(Json(result)); }
public static dynamic Route(this object runLog, IDataCache cache = null) { dynamic dynRunLog = runLog as dynamic; var routeId = (long)dynRunLog.RouteId; Func <dynamic> getRouteFunc = () => new Route().Single(routeId); return(cache == null?getRouteFunc() : cache.Get($"route.{routeId}", getRouteFunc)); }
public void UseCache(IDataCache userSalesCache) { _userSalesCache = userSalesCache; Dictionary <int, string> headers = _userSalesCache.Get <Dictionary <int, string> >(DataCacheKey.Headers); if (headers.Count > 0) { _csvReader.SetHeader(headers); } }
/// <summary> /// 获得数据 /// </summary> /// <param name="o"></param> /// <returns></returns> private IList <T_User> AnsycbackForCache() { IList <T_User> list = new List <T_User>(); //IDataCache cache = DataCache.RInstance; var Mfristkey1 = cache.Get <string>("Mfristkey1"); if (Mfristkey1 != null) { cache.Delete("Mfristkey1"); } if (cache.Get <IList <T_User> >("list") != null) { list = cache.Get <IList <T_User> >("list"); } else { list = _user.GetAll(x => x.IsDeleted == false); cache.Set <IList <T_User> >("list", list, DateTime.Now.AddMinutes(2)); } return(list); }
public void TestContains() { Assert.IsTrue(_cache.Contains("k1")); Assert.AreEqual("Test simple value 1", _cache.Get <string>("k1")); Assert.IsTrue(_cache.Contains("k2")); Assert.AreEqual("Test simple value 2", _cache.Get <string>("k2")); Assert.IsTrue(_cache.Contains("k3")); Assert.AreEqual("Test simple value 3", _cache.Get <string>("k3")); }
public TResult Handle(TQuery query) { if (string.IsNullOrEmpty(query.CacheKey)) { return(_decoratedHndl.Handle(query)); } else { TResult res = _cache.Get <TResult>(query.CacheKey); if (res == null) { lock (_cache) { res = _cache.Get <TResult>(query.CacheKey); if (res == null) { res = _decoratedHndl.Handle(query); _cache.Set(query.CacheKey, res, query.CacheExpirationTime); } } } return(res); } }
public async Task <Lookups> GetAll() { if (!_cache.Contains(DataCacheKey.Lookups)) { var models = new Lookups { Genders = GetEnumOutput(Gender.Female), }; //return await Task.Run(() => models); _cache.Insert(DataCacheKey.Lookups, models); } return(await Task.Run(() => _cache.Get <Lookups>(DataCacheKey.Lookups))); //var models = _cache.Get<Lookups>(DataCacheKey.Lookups); //return await Task.Run(() => models); }
/// <summary> /// <summary> /// 获取缓存,不加入CacheKeyAll管理 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="cacheKey"></param> /// <returns></returns> protected T GetCache <T>(string cacheKey) { T obj = default(T); string val = ""; try { obj = cacheHelper.Get <T>(cacheKey); val = obj.ToString(); return(obj); } catch (Exception ex) { LogHelper.Info(this.GetType(), "缓存错误,出错Key:" + cacheKey + ";出错value;" + val + "|" + ex.Message); } return(default(T)); }
public async Task <T3> FindAsync <T, T2, T3>(T2 id) where T : BaseDataEntity <T2, T3> where T3 : class { //if (_dataCache.Contains<T3, T2>(id)) //{ // return _dataCache.Get<T3, T2>(id); //} if (!_dataCache.Contains <T, T2, T3>()) { var items = await Set <T>().ToListAsync(); _dataCache.Add <T, T2, T3>(items); } var dataItem = _dataCache.Get <T, T2, T3>(id); //if (dataItem != null) //{ // var item = dataItem.Deserialize(); // _dataCache.Add(id,item); // return item; //} return(dataItem?.Deserialize()); }
public async Task <T> GetAsync <T>(string principal) where T : EventSourcedRootEntity { var instance = _cache.Get(principal); if (instance is T result) { return(result); } var eventLog = await _eventStore.GetEventLogAsync(principal); var constructor = typeof(T).GetConstructor(new[] { typeof(IEnumerable <IDomainEvent>), typeof(int) }); if (constructor == null) { throw new InvalidOperationException($"A constructor for type '{typeof(T)}' was not found."); } var obj = constructor.Invoke(new object[] { eventLog, 1 }) as T; _cache.TryAdd(principal, obj); return(obj); }
/// <summary> /// 获取令牌信息,根据手机号 /// </summary> /// <param name="phone">手机号</param> /// <returns>令牌信息</returns> public static TokenInfo GetToken(string phone) { return(RedisCache.Get <TokenInfo>(phone)); }
/// <summary> /// Creates an instance of the <see cref="FilterResult"/> class and populates it with data from the <see cref="Filter"/> model class. /// </summary> public async Task <FilterResult> GetCompactionFilter( Guid projectUid, string projectTimeZone, string userUid, Guid?filterUid, IHeaderDictionary customHeaders, bool filterMustExist = false) { var filterKey = filterUid.HasValue ? $"{nameof(FilterResult)} {filterUid.Value}" : string.Empty; // Filter models are immutable except for their Name. // This service doesn't consider the Name in any of it's operations so we don't mind if our // cached object is out of date in this regard. var cachedFilter = filterUid.HasValue ? _filterCache.Get <FilterResult>(filterKey) : null; if (cachedFilter != null) { cachedFilter.ApplyDateRange(projectTimeZone, true); return(cachedFilter); } var excludedSs = await _designUtilities.GetExcludedSurveyedSurfaceIds(projectUid, userUid, customHeaders); var excludedIds = excludedSs?.Select(e => e.Item1).ToList(); var excludedUids = excludedSs?.Select(e => e.Item2).ToList(); bool haveExcludedSs = excludedSs != null && excludedSs.Count > 0; if (!filterUid.HasValue) { return(haveExcludedSs ? FilterResult.CreateFilter(excludedIds, excludedUids) : null); } try { DesignDescriptor designDescriptor = null; DesignDescriptor alignmentDescriptor = null; var filterData = await GetFilterDescriptor(projectUid, filterUid.Value, customHeaders); if (filterMustExist && filterData == null) { throw new ServiceException(HttpStatusCode.BadRequest, new ContractExecutionResult(ContractExecutionStatesEnum.ValidationError, "Invalid Filter UID.")); } if (filterData != null) { _log.LogDebug($"Filter from Filter Svc: {JsonConvert.SerializeObject(filterData)}"); if (filterData.DesignUid != null && Guid.TryParse(filterData.DesignUid, out Guid designUidGuid)) { designDescriptor = await _designUtilities.GetAndValidateDesignDescriptor(projectUid, designUidGuid, userUid, customHeaders); } if (filterData.AlignmentUid != null && Guid.TryParse(filterData.AlignmentUid, out Guid alignmentUidGuid)) { alignmentDescriptor = await _designUtilities.GetAndValidateDesignDescriptor(projectUid, alignmentUidGuid, userUid, customHeaders); } if (filterData.HasData() || haveExcludedSs || designDescriptor != null) { filterData.ApplyDateRange(projectTimeZone, true); var layerMethod = filterData.LayerNumber.HasValue ? FilterLayerMethod.TagfileLayerNumber : FilterLayerMethod.None; bool?returnEarliest = null; if (filterData.ElevationType == ElevationType.First) { returnEarliest = true; } var raptorFilter = new FilterResult(filterUid, filterData, filterData.PolygonLL, alignmentDescriptor, layerMethod, excludedIds, excludedUids, returnEarliest, designDescriptor); _log.LogDebug($"Filter after filter conversion: {JsonConvert.SerializeObject(raptorFilter)}"); // The filter will be removed from memory and recalculated to ensure we have the latest filter on any relevant changes var filterTags = new List <string>() { filterUid.Value.ToString(), projectUid.ToString() }; _filterCache.Set(filterKey, raptorFilter, filterTags, _filterCacheOptions); return(raptorFilter); } } } catch (ServiceException ex) { _log.LogDebug($"EXCEPTION caught - cannot find filter {ex.Message} {ex.GetContent} {ex.GetResult.Message}"); throw; } catch (Exception ex) { _log.LogDebug("EXCEPTION caught - cannot find filter " + ex.Message); throw; } return(haveExcludedSs ? FilterResult.CreateFilter(excludedIds, excludedUids) : null); }
public dynamic FindUser(long userId, IDataCache dataCache) { Func <dynamic> findUserFunc = () => new UserAccount().Single(userId); return(dataCache == null?findUserFunc() : dataCache.Get($"user.{userId}", findUserFunc)); }
public PlaygroundProcessor LoadPlaygroundFromCache(string ticker, int strategyId) { var key = $"LoadPlaygroundAsync-{ticker}-{strategyId}"; return(_cache.Get <PlaygroundProcessor>(key)); }