/// <summary> /// 构造函数 /// </summary> private DNTCache() { if (MemCachedConfigs.GetConfig() != null && MemCachedConfigs.GetConfig().ApplyMemCached) { applyMemCached = true; } if (RedisConfigs.GetConfig() != null && RedisConfigs.GetConfig().ApplyRedis) { applyRedis = true; } if (applyMemCached || applyRedis) { try { cs = cachedStrategy = (ICacheStrategy)Activator.CreateInstance(Type.GetType("Discuz.EntLib." + (applyMemCached ? "MemCachedStrategy" : "RedisStrategy") + ", Discuz.EntLib", false, true)); } catch { throw new Exception("请检查Discuz.EntLib.dll文件是否被放置在bin目录下并配置正确"); } } else { cs = new DefaultCacheStrategy(); objectXmlMap = rootXml.CreateElement("Cache"); //建立内部XML文档. rootXml.AppendChild(objectXmlMap); } }
/// <summary> /// 返回指定ID的对象 /// </summary> /// <param name="objId"></param> /// <returns></returns> public override object RetrieveObject(string objId) { object obj = base.RetrieveObject(objId); if (obj == null) { using (IRedisClient Redis = RedisManager.GetClient()) { obj = new ObjectSerializer().Deserialize(Redis.Get <byte[]>(objId)); if (obj != null && !objId.StartsWith("/Forum/ShowTopic/")) //对ShowTopic页面缓存数据不放到本地缓存 { if (objId.StartsWith("/Forum/ShowTopicGuestCachePage/")) //对游客缓存页面ShowTopic数据缓存设置有效时间 { base.TimeOut = GeneralConfigs.GetConfig().Guestcachepagetimeout * 60; } if (objId.StartsWith("/Forum/ShowForumGuestCachePage/"))//对游客缓存页面ShowTopic数据缓存设置有效时间 { base.TimeOut = RedisConfigs.GetConfig().CacheShowForumCacheTime * 60; } else { base.TimeOut = LocalCacheTime; } base.AddObject(objId, obj, TimeOut); } } } return(obj); }
/// <summary> /// 构造函数 /// </summary> private DNTCache() { if (MemCachedConfigs.GetConfig() != null && MemCachedConfigs.GetConfig().ApplyMemCached) { applyMemCached = true; } if (RedisConfigs.GetConfig() != null && RedisConfigs.GetConfig().ApplyRedis) { applyRedis = true; } if (LLServerConfigs.GetConfig() != null && LLServerConfigs.GetConfig().ApplyLLServer) { applyLLServer = true; } if (applyMemCached || applyRedis || applyLLServer) { try { string cacheStratetyName; if (applyMemCached) { cacheStratetyName = "MemCachedStrategy"; } else if (applyRedis) { cacheStratetyName = "RedisStrategy"; } else { cacheStratetyName = "LLStrategy"; } cs = cachedStrategy = (ICacheStrategy)Activator.CreateInstance(Type.GetType("Discuz.EntLib." + cacheStratetyName + ", Discuz.EntLib", false, true)); } catch { throw new Exception("请检查Discuz.EntLib.dll文件是否被放置在bin目录下并配置正确"); } } else { cs = new DefaultCacheStrategy(); if (rootXml.HasChildNodes) { rootXml.RemoveAll(); } objectXmlMap = rootXml.CreateElement("Cache"); //建立内部XML文档. rootXml.AppendChild(objectXmlMap); } }
/// <summary> /// 获取主题所包含的Tag /// </summary> /// <param name="topicid">主题Id</param> /// <returns>List</returns> public static List <TagInfo> GetTagsListByTopic(int topicid) { List <TagInfo> tabInfoList = null; //只有在开启memcached时才会缓存tag标签 if ((MemCachedConfigs.GetConfig() != null && MemCachedConfigs.GetConfig().ApplyMemCached) || (RedisConfigs.GetConfig() != null && RedisConfigs.GetConfig().ApplyRedis)) { DNTCache cache = DNTCache.GetCacheService(); tabInfoList = cache.RetrieveObject("/Forum/ShowTopic/Tag/" + topicid + "/") as List <TagInfo>; if (tabInfoList == null) { tabInfoList = Discuz.Data.ForumTags.GetTagsListByTopic(topicid); cache.AddObject("/Forum/ShowTopic/Tag/" + topicid + "/", tabInfoList); } } else { tabInfoList = Discuz.Data.ForumTags.GetTagsListByTopic(topicid); } return(tabInfoList); }