zoukankan      html  css  js  c++  java
  • 如何配置sqlcachedependence

    在vs2008工具下:aspnet_regsql -S localhost -E -d MSPetShop4 -ed

    启动sql缓存

    配置webconfig

    在<connectionStrings>下添加数据库链接
        <add name="SQLConnString1" connectionString="server=.;user id=sa;password=sa;database=student;min pool size=4;max pool size=4;packet size=3072" providerName="System.Data.SqlClient"/>


      </connectionStrings>

     在<system.web>下添加如下代码

        <caching>
          <sqlCacheDependency enabled="true" pollTime="10000">
            <databases>
              <add name="student" connectionStringName="SQLConnString1" pollTime="10000"/>
            </databases>
          </sqlCacheDependency>
        </caching>
     使用如下语句允许某个表可以进行缓存

    System.Web.Caching.SqlCacheDependencyAdmin.EnableTableForNotifications("server=.;uid=sa;pwd=sa;database=student", "student");

    进行缓存代码的添加

    if (Cache["sqlcache"] == null)
                {
                    System.Web.Caching.AggregateCacheDependency agr = new System.Web.Caching.AggregateCacheDependency();
                    System.Web.Caching.SqlCacheDependency sql1 = new System.Web.Caching.SqlCacheDependency("student", "student");
                   
                    agr.Add(sql1);
                    Cache.Add("sqlcache", DateTime.Now, agr, DateTime.Now.AddHours(1), System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.High, null);
                    Response.Write("无缓存");
                }
                else
                {
                    Response.Write("有缓存");
                    Response.Write(Cache["sqlcache"].ToString());
                }

  • 相关阅读:
    第八天
    第六天 yum 磁盘分区与格式化
    第五天 权限掩码vim编辑器 软件包安装和管理
    第12组 Alpha冲刺 总结
    第12组 Alpha冲刺(6/6)
    第12组 Alpha冲刺(5/6)
    第12组 Alpha冲刺(4/6)
    第12组 Alpha冲刺(3/6)
    第12组 Alpha冲刺(2/6)
    第12组 Alpha冲刺(1/6)
  • 原文地址:https://www.cnblogs.com/qiejinxing/p/1830307.html
Copyright © 2011-2022 走看看