protected virtual DataRow GetRandomBook() { DataCache cache = CacheFactory.GetCache(); DataTable dt = (DataTable)cache["BooksTable"]; if (dt == null) { string path = SiteUtilities.MapPath(BookXML); DataSet ds = new DataSet(); ds.ReadXml(path); dt = ds.Tables[0]; cache.Insert("BooksTable", dt, new CacheDependency(path)); } int seed = DateTime.Now.Millisecond; //if we add more than one control to the page, we want to make sure our seeds are unique if (this.ID != null) { seed += this.ID.GetHashCode(); } //Not really random...but good enough Random rnd = new Random(seed); return(dt.Rows[rnd.Next(dt.Rows.Count)]); }
public SeoMetaTags GetMetaTags() { var cache = CacheFactory.GetCache(); var seoMetaTags = cache["seoMetaTags"] as SeoMetaTags; if (seoMetaTags == null) { seoMetaTags = GetMetaTagsFromConfig(); cache.Insert("seoMetaTags", seoMetaTags, new System.Web.Caching.CacheDependency(MetaConfigFile)); } return(seoMetaTags); }
public static HashSet <string> GetBlockedIPs(HttpContext context) { DataCache cache = CacheFactory.GetCache(); HashSet <string> ips = (HashSet <string>)cache[BLOCKEDIPSCACHEKEY]; if (ips == null) { ips = GetBlockedIPs(GetBlockedIPsFilePathFromCurrentContext(context)); cache.Insert(BLOCKEDIPSCACHEKEY, ips, new CacheDependency(GetBlockedIPsFilePathFromCurrentContext(context))); } return(ips); }
public static RobotDefinition GetRobotDefinition() { DataCache cache = CacheFactory.GetCache(); RobotDefinition definition = (RobotDefinition)cache["RobotDefinition"]; if (definition == null) { definition = GetRobotDefinition(GetConfigFilePathFromCurrentContext()); cache.Insert("RobotDefinition", definition, new CacheDependency(GetConfigFilePathFromCurrentContext())); } return(definition); }
protected StringReader GetCachedTemplate(string key, string filePath) { DataCache cache = CacheFactory.GetCache(); string cachedtemplate = cache[key] as string; if (cachedtemplate == null || cachedtemplate.Length == 0) { if (filePath == null) { return(null); } using (StreamReader reader = new StreamReader(filePath, true)) { cachedtemplate = reader.ReadToEnd(); } cache.Insert(key, cachedtemplate, new System.Web.Caching.CacheDependency(filePath)); } return(new StringReader(cachedtemplate)); }
private void HandleBeginRequest(object sender, EventArgs evargs) { HttpApplication app = sender as HttpApplication; DataCache cache = CacheFactory.GetCache(); // need to exclude deleteItem.ashx from URL Rewriting so we can find the permalink for other dasBlog sites if (app != null && app.Context.Request.Url.LocalPath.ToLower().EndsWith("deleteitem.ashx") == false) { // changed this to support 'c#' as a category name Uri requestUri = app.Context.Request.Url; string requestUrl = app.Context.Request.Path + (requestUri.Query != null && requestUri.Query.Length > 0 ? requestUri.Query : ""); // bypass the mapping use the cached mapping string mapToFromCache = cache[requestUrl] as string; if (mapToFromCache != null && mapToFromCache.Length > 0) { app.Context.RewritePath(mapToFromCache); return; } // no cached mapping proceed as usual NameValueCollection urlMaps = (NameValueCollection)ConfigurationManager.GetSection(UrlMapperModuleSectionHandler.ConfigSectionName); if (urlMaps != null) { for (int loop = 0; loop < urlMaps.Count; loop++) { string matchExpression = urlMaps.GetKey(loop); Regex regExpression = new Regex(matchExpression, RegexOptions.IgnoreCase | RegexOptions.Singleline | RegexOptions.CultureInvariant | RegexOptions.Compiled); Match matchUrl = regExpression.Match(requestUrl); if (matchUrl != null && matchUrl.Success) { bool isCategoryQuery = false; string mapTo = urlMaps[matchExpression]; // Regex regMap = new Regex("\\{(?<expr>\\w+)\\}"); foreach (Match matchExpr in regMap.Matches(mapTo)) { Group urlExpr; string expr = matchExpr.Groups["expr"].Value; urlExpr = matchUrl.Groups[expr]; if (urlExpr != null) { if (urlExpr.Value == "category") { isCategoryQuery = true; } if (expr == "value" & isCategoryQuery) { string queryParams = urlExpr.Value; // OmarS: hacking the category expression to support a page parameter. if (queryParams.IndexOf(",") != -1) { int pos = queryParams.LastIndexOf(","); string pageNumber = queryParams.Substring(queryParams.LastIndexOf(",") + 1, queryParams.Length - (pos + 1)); string categoryList = ""; if (Char.IsDigit(pageNumber, 0)) { categoryList = queryParams.Substring(0, pos); } else { categoryList = queryParams; } categoryList = categoryList.Replace(",", "|"); mapTo = mapTo.Replace("{" + expr + "}", app.Server.UrlEncode(categoryList)); mapTo = mapTo + "&page=" + pageNumber; } else { string categoryList = urlExpr.Value.Replace(",", "|"); mapTo = mapTo.Replace("{" + expr + "}", categoryList); } } else { mapTo = mapTo.Replace("{" + expr + "}", urlExpr.Value); } } } // micro cache the mapped url cache.Insert(requestUrl, mapTo, new TimeSpan(0, 0, 0, 5)); app.Context.RewritePath(mapTo); break; } } } } }