public static NItem GetPageFromCache(string pageId, NOutputCache module) { CachePageRequest pageReq = _pageReqTbl[pageId] as CachePageRequest; if (pageReq == null) { pageReq = new CachePageRequest(pageId); lock (_pageReqTbl.SyncRoot) { if (!_pageReqTbl.Contains(pageId)) { _pageReqTbl.Add(pageId, pageReq); } } } return(pageReq.FetchPage(module)); }
/// <summary> /// Loads page settings from config /// </summary> public void LoadPageSettings() { NCacheSection section = new NCacheSection(); XmlNode ncacheSection = section.NCacheConfigSection; if (ncacheSection != null) { XmlNode settings = ncacheSection.SelectSingleNode("outputCacheSettings"); if (settings != null) { XmlNode outputCachePages = settings.SelectSingleNode("outputCachePages"); if (outputCachePages != null) { XmlNodeList pageList = outputCachePages.SelectNodes("add"); foreach (XmlNode node in pageList) { PageSettings pageSettings = new PageSettings(); if (node.Attributes["name"] != null && node.Attributes["name"].Value != string.Empty) { pageSettings.PageName = node.Attributes["name"].Value.ToLower(); } else { throw new ConfigurationException("The 'name' attribute in outputCachePages section cannot be null or empty string"); } if (node.Attributes["duration"] != null) { try { pageSettings.ExpirationTime = Convert.ToInt32(node.Attributes["duration"].Value); } catch (Exception exc) { throw new ConfigurationException("The value of property 'duration' cannot be parsed. The error is: " + exc.Message); } } else { throw new ConfigurationException("The 'duration' attribute in outputCachePages section cannot be null"); } if (node.Attributes["enabled"] != null) { if (node.Attributes["enabled"].Value != "true" && node.Attributes["enabled"].Value != "false") { throw new ConfigurationException("The 'enabled' attribute in outputCachePages section must be one of the following values: true, false."); } else { pageSettings.CachingEnabled = Convert.ToBoolean(node.Attributes["enabled"].Value); } } if (node.Attributes["requestType"] != null) { string requestType = node.Attributes["requestType"].Value.ToLower(); if (!NOutputCache.IsNullOrEmpty(requestType)) { string[] split = requestType.Split('/'); for (int i = 0; i < split.Length; i++) { switch (split[i].Trim()) { case "get": pageSettings.Get = true; break; case "post": pageSettings.Post = true; break; } } } else { pageSettings.Get = true;///by default } } if (node.Attributes["varyByParam"] != null) { pageSettings.ParseVaryByParams(node.Attributes["varyByParam"].Value); } if (node.Attributes["varyByHeader"] != null) { pageSettings.ParseVaryByHeaders(node.Attributes["varyByHeader"].Value); } if (node.Attributes["varyByCustom"] != null) { pageSettings.VaryByCustom = node.Attributes["varyByCustom"].Value.ToLower(); } this._pageProps[pageSettings.PageName] = pageSettings; } } } } }