public async Task <DropshipAccount> GetAccount(string username) { //Check cache for account info var accountInfo = new DropshipAccount() { Username = username }; if (await cache.Exists(RedisKeyConvert.Serialize(accountInfo))) { return(JsonConvert.DeserializeObject <DropshipAccount>(await cache.GetString(RedisKeyConvert.Serialize(accountInfo)))); } //Couldn't find it in the cache, look in db accountInfo = await dbAccounts.GetOneByUsername(username); if (accountInfo != null) { return(accountInfo); } //Couldn't find it in db, must be a new account accountInfo = new DropshipAccount() { Username = username, Status = AccountStatus.New }; return(accountInfo); }
async Task <string> getUncertain(SearchCriteria criteria) { var key = $"{RedisKeyConvert.Serialize(criteria, "servicekey")}:uncertain"; var items = await cache.GetString(key); return(items ?? "[]"); }
async Task <bool> existItemSearch(SearchCriteria criteria, int page) { var crit = JsonConvert.DeserializeObject <SearchCriteria>(JsonConvert.SerializeObject(criteria)); crit.Page = page; var key = RedisKeyConvert.Serialize(crit); return(await cache.Exists(key)); }
public async Task CacheSearch(SearchCriteria criteria, WebSearchService[] services, SearchResultOverview result) { var key = RedisKeyConvert.Serialize(criteria); //Cache the search & service models try { await cacheItemSearch(criteria, result); await cacheServices(services); } catch (Exception e) { var sentry = new SentryEvent(e); sentry.Message = $"Error when saving to cache: {e.Message}"; await raven.CaptureNetCoreEventAsync(sentry); } }
public async Task <SearchResultOverview> SearchItems(SearchCriteria search) { //Check for cached item list string key = RedisKeyConvert.Serialize(search); SearchResultOverview result = null; try { storeSearchHistory(search); if (await cache.Exists(key)) { var cachedResult = JsonConvert.DeserializeObject <SearchResultOverview>(await cache.GetString(key)); result = cachedResult; } else { await SearchServiceProvider.RetrieveSearchServices(services, cache, search, allNew : true); var results = await SearchDispatcher.Search(services, new int[] { search.Page }); var formattedResults = SearchFormatter.FormatResults(0, results); await searchCache.CacheSearch(search, services, formattedResults.Results); result = formattedResults.Results; } searchCache.StartCacheJob(search, null); } catch (Exception e) { await raven.CaptureNetCoreEventAsync(e); } return(result); }
public string GetRedisKey() { return($"{RedisKeyConvert.Serialize(this.Criteria, "servicekey")}:{this.Type.ToString()}"); }
async Task cacheUncertain(SearchCriteria criteria, IEnumerable <Item> items) { var key = $"{RedisKeyConvert.Serialize(criteria, "servicekey")}:uncertain"; await cache.StoreString(key, JsonConvert.SerializeObject(items)); }
async Task cacheItemSearch(SearchCriteria criteria, SearchResultOverview result) { var key = RedisKeyConvert.Serialize(criteria); await cache.StoreString(key, JsonConvert.SerializeObject(result)); }