Exemplo n.º 1
0
        private static SPListQueryCachedData GetListQueryCachedData(SPList list, string viewXml)
        {
            SPListQueryCachedData listQueryCachedData = GetListQueryCachedData(list);

            if (!string.IsNullOrEmpty(viewXml))
            {
                listQueryCachedData.Add(Guid.NewGuid().ToString(), viewXml);
            }

            return(listQueryCachedData);
        }
Exemplo n.º 2
0
        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);
        }