Пример #1
0
        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);
        }
Пример #2
0
        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();
        }
Пример #3
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);
        }