public ICachedObject <DataTable> GetDataCache(string keyQuery, Func <DataTable> loader) { if (Queries.ContainsKey(keyQuery)) { return(SPCache.Cache(loader) .By(keyQuery, this.ListId.ToString(), this.WebId.ToString(), this.SiteId.ToString(), this.UserId)); } return(null); }
public void Clear() { foreach (var cache in this.Queries.Keys.Select(key => SPCache.Cache <DataTable>(null) .By(key, this.ListId.ToString(), this.WebId.ToString(), this.SiteId.ToString()) .By(UserId)).Where(cache => cache != null)) { cache.Clear(); } this.Queries.Clear(); }
private DataTable GetData(SPList list, SPQuery query) { if (string.IsNullOrEmpty(query.ViewFields)) { throw new ArgumentException("The ViewFields property for SPQuery hasn't been set."); } string viewXml = XElement.Parse(query.ViewXml, LoadOptions.None).ToString(SaveOptions.DisableFormatting); ICachedObject <SPListQueryCachedData> queryCache = SPCache.Cache(() => GetListQueryCachedData(list, viewXml)) .By(list.ID.ToString(), list.ParentWeb.ID.ToString(), list.ParentWeb.Site.ID.ToString(), list.ParentWeb.CurrentUser.Sid); if (CacheTime != default(TimeSpan)) { queryCache.ForSliding(CacheTime); } SPListQueryCachedData listQueryCachedData = queryCache.CachedObject; string keyQuery; if (HasListChanged(list, listQueryCachedData)) { listQueryCachedData.Clear(); listQueryCachedData = GetListQueryCachedData(list); keyQuery = Guid.NewGuid().ToString(); listQueryCachedData.Add(keyQuery, viewXml); queryCache.CachedObject = listQueryCachedData; queryCache.Update(); } else { keyQuery = listQueryCachedData.FindKey(viewXml); } ICachedObject <DataTable> dataCache = listQueryCachedData.GetDataCache(keyQuery, () => LoadDataTable(list, query)); if (CacheTime != default(TimeSpan)) { dataCache.ForSliding(CacheTime); } return(dataCache.CachedObject); }