예제 #1
0
        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);
        }
예제 #2
0
        async Task <string> getUncertain(SearchCriteria criteria)
        {
            var key = $"{RedisKeyConvert.Serialize(criteria, "servicekey")}:uncertain";

            var items = await cache.GetString(key);

            return(items ?? "[]");
        }
예제 #3
0
        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));
        }
예제 #4
0
        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);
            }
        }
예제 #5
0
        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);
        }
예제 #6
0
 public string GetRedisKey()
 {
     return($"{RedisKeyConvert.Serialize(this.Criteria, "servicekey")}:{this.Type.ToString()}");
 }
예제 #7
0
        async Task cacheUncertain(SearchCriteria criteria, IEnumerable <Item> items)
        {
            var key = $"{RedisKeyConvert.Serialize(criteria, "servicekey")}:uncertain";

            await cache.StoreString(key, JsonConvert.SerializeObject(items));
        }
예제 #8
0
        async Task cacheItemSearch(SearchCriteria criteria, SearchResultOverview result)
        {
            var key = RedisKeyConvert.Serialize(criteria);

            await cache.StoreString(key, JsonConvert.SerializeObject(result));
        }