Exemplo n.º 1
0
        public static int GetStoryCount(int hostID, bool isPublished, DateTime startDate, DateTime endDate)
        {
            string cacheKey = String.Format("Kick_StoryCount_{0}_{1}_{2}_{3}", isPublished, hostID, CacheHelper.DateTimeToCacheKey(startDate), CacheHelper.DateTimeToCacheKey(endDate));
            CacheManager <string, int?> storyCountCache = GetCountCache();

            int storyCount;

            if (storyCountCache.ContainsKey(cacheKey))
            {
                storyCount = storyCountCache[cacheKey].Value;
            }
            else
            {
                storyCount = Story.GetStoryCount(hostID, isPublished, startDate, endDate);
                storyCountCache.Insert(cacheKey, storyCount, CacheHelper.CACHE_DURATION_IN_SECONDS);
            }

            return(storyCount);
        }
Exemplo n.º 2
0
        public static int GetStoryCollectionSearchResultsCountByUser(string query, string username, int hostId, int page, int pageSize)
        {
            string cacheKey = string.Format("SearchUserStoryCollectionCount_{0}_{1}_{2}", CleanUpQuery(query), hostId, username);

            CacheManager <string, int?> cache = GetSearchStoryCountCache();
            int searchResultsCount;

            if (cache.ContainsKey(cacheKey))
            {
                searchResultsCount = cache[cacheKey].Value;
            }
            else
            {
                //call the search to populate the count cache
                GetStoryCollectionSearchResultsByUser(query, username, hostId, page, pageSize);
                searchResultsCount = cache[cacheKey].Value;
            }

            return(searchResultsCount);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Searches the index for stories kicked by a given user
        /// </summary>
        /// <param name="query"></param>
        /// <param name="username"></param>
        /// <param name="hostId"></param>
        /// <param name="page"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public static StoryCollection GetStoryCollectionSearchResultsByUser(string query, string username, string sortField,
                                                                            bool sortReversed, int hostId, int page, int pageSize)
        {
            string cacheKey = string.Format("SearchUserStoryCollection_{0}_{1}_{2}_{3}_{4}_{5}_{6}",
                                            CleanUpQuery(query),
                                            hostId,
                                            page,
                                            pageSize,
                                            username,
                                            sortField,
                                            sortReversed);

            string cacheCountKey = string.Format("SearchUserStoryCollectionCount_{0}_{1}_{2}", CleanUpQuery(query), hostId, username);

            CacheManager <string, StoryCollection> cache = GetSearchStoryCollectionCache();
            StoryCollection results = cache[cacheKey];

            if (results == null)
            {
                int         totalNumberResults = 0;
                SearchQuery searchQuery        = new SearchQuery();
                results = searchQuery.SearchIndex(hostId, query, username, page, pageSize, sortField, sortReversed, out totalNumberResults);

                if (results != null)
                {
                    cache.Insert(cacheKey, results, CacheHelper.CACHE_DURATION_IN_SECONDS);
                }

                //add to the cache containing the search results counts, we dont want to have to call the
                //the search twice since we already have this value in this method call.
                CacheManager <string, int?> cacheCount = GetSearchStoryCountCache();
                if (cacheCount.ContainsKey(cacheCountKey))
                {
                    cacheCount.Remove(cacheCountKey);
                }

                cacheCount.Insert(cacheCountKey, totalNumberResults, CacheHelper.CACHE_DURATION_IN_SECONDS);
            }

            return(results);
        }