/// <summary>Append the response page to the cached data.</summary> public virtual void CacheRequestPage(RequestFilter filter, RequestPage <ModProfile> page) { // early out if shouldn't cache if (!this.isCachingPermitted) { return; } // asserts Debug.Assert(filter != null); Debug.Assert(page != null); // cache request string filterString = filter.GenerateFilterString(); RequestPageData cachedData; if (this.requestCache.TryGetValue(filterString, out cachedData)) { cachedData.resultTotal = page.resultTotal; this.requestCache[filterString] = RequestPageData.Append(cachedData, page.resultOffset, Utility.MapProfileIds(page.items)); } else { cachedData = new RequestPageData() { resultOffset = page.resultOffset, resultTotal = page.resultTotal, modIds = Utility.MapProfileIds(page.items), }; this.requestCache.Add(filterString, cachedData); } // cache profiles foreach (ModProfile profile in page.items) { this.profileCache[profile.id] = profile; } // store if (this.storeIfSubscribed) { IList <int> subMods = ModManager.GetSubscribedModIds(); foreach (ModProfile profile in page.items) { if (subMods.Contains(profile.id)) { CacheClient.SaveModProfile(profile); } } } }
/// <summary>Appends a collection of ids to a RequestPageData.</summary> public static RequestPageData Append(RequestPageData pageData, int appendCollectionOffset, int[] appendCollection) { if (appendCollection == null || appendCollection.Length == 0) { return(pageData); } // asserts Debug.Assert(appendCollectionOffset >= 0); Debug.Assert(appendCollectionOffset + appendCollection.Length <= pageData.resultTotal); // calc last indicies int newOffset = (appendCollectionOffset < pageData.resultOffset ? appendCollectionOffset : pageData.resultOffset); int oldLastIndex = pageData.modIds.Length + pageData.resultOffset - 1; int appendingLastIndex = appendCollection.Length + appendCollectionOffset - 1; int newLastIndex = (appendingLastIndex > oldLastIndex ? appendingLastIndex : oldLastIndex); // fill array int[] newArray = new int[newLastIndex - newOffset + 1]; for (int i = 0; i < newArray.Length; ++i) { newArray[i] = ModProfile.NULL_ID; } Array.Copy(pageData.modIds, 0, newArray, pageData.resultOffset - newOffset, pageData.modIds.Length); Array.Copy(appendCollection, 0, newArray, appendCollectionOffset - newOffset, appendCollection.Length); // Create appended page data RequestPageData retData = new RequestPageData() { resultOffset = newOffset, resultTotal = pageData.resultTotal, modIds = newArray, }; return(retData); }
/// <summary>Append the response page to the cached data.</summary> public virtual void CacheRequestPage(RequestFilter filter, RequestPage <ModProfile> page) { // early out if shouldn't cache if (!this.isCachingPermitted) { return; } // asserts Debug.Assert(filter != null); Debug.Assert(page != null); // cache request string filterString = filter.GenerateFilterString(); RequestPageData cachedData; if (this.requestCache.TryGetValue(filterString, out cachedData)) { cachedData.resultTotal = page.resultTotal; this.requestCache[filterString] = RequestPageData.Append(cachedData, page.resultOffset, Utility.MapProfileIds(page.items)); } else { cachedData = new RequestPageData() { resultOffset = page.resultOffset, resultTotal = page.resultTotal, modIds = Utility.MapProfileIds(page.items), }; this.requestCache.Add(filterString, cachedData); } // cache profiles this.CacheModProfiles(page.items); }