首页 新闻 搜索 专区 学院

基于存储过程的Notification模式的缓存怎么做?

0
悬赏园豆:5 [已关闭问题] 关闭于 2015-06-11 16:56

private static MvcHtmlString GetMvcHtmlBySpOrCache(Func<MvcHtmlString> fun, string cacheKey, string spName)
        {
            if (CacheHelper.IsCached(cacheKey))
            {
                return CacheHelper.GetCacheValue(cacheKey) as MvcHtmlString;
            }

            SqlCacheDependency myDependency;
            string conString = WebConfigurationManager.ConnectionStrings["Db"].ConnectionString;
            using (SqlConnection connection = new SqlConnection(conString))
            {
                using (SqlCommand cmd = connection.CreateCommand())
                {
                    cmd.CommandText = spName;
                    cmd.CommandType = CommandType.StoredProcedure;
                    myDependency = new SqlCacheDependency(cmd);
                }
            }

            MvcHtmlString mvcHtmlString = fun();
            CacheHelper.AddCacheForever(cacheKey, mvcHtmlString, myDependency);
            return mvcHtmlString;
        }

以上代码不起作用,缓存后,更新数据后,缓存并不失效。:(

存储过程类似这样:


    --SET NOCOUNT ON;

    select top 24 a.x, COUNT(b.y) as count
    from dbo.XX a
        inner join dbo.YY b on b.mm = a.mm
    group by a.x
    order by a.Id desc;

灰灰狼的主页 灰灰狼 | 初学一级 | 园豆:5
提问于:2012-01-27 15:25
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册