• 缓存之SqlDependency


    指定缓存失效的数据库依赖项。可以具体到数据库和表。

    具体配置具体要经过几个步骤:

    1.   注册连接池

    命令:aspnet_regsql -S 192.168.30.220"SQL2K -U sa -P sa -ed -d pubs -et -t test专门注册连接池的工具 在sql数据库的数据 库改变了,才改变缓存。

    参数:

          _s 制定注册的服务器;      _u和 _p 说明是sql数据库的授权模式;      _d 指定数据库的名字;       _ed 说明缓存生效。

    示例:

             aspnet_regsql -S 192.168.30.220"SQL2K -U sa -P sa -ed -d pubs -et -t test

          进行outputcache配置
         <%@ OutputCache SqlDependency="pubs:test" Duration="100" VaryByParam="id"%>

    2.  设置WebConfig      

        <connectionStrings>

               <add name="mySqlServer" connectionString="Server=192.168.30.220"SQL2K;Database=pubs;uid=sa;pwd=sa;"/> 

        </connectionStrings>

    3.       

      <caching>

        <sqlCacheDependency enabled="true">

              <databases>

                <add connectionStringName="mySqlServer"  pollTime="500" />

              </databases>

            </sqlCacheDependency>

    </caching>

      name:必须是数据库的名字;   connectionStringName:连接字符串的名称

      除了可以建立数据库依赖,还可以建立文件依赖或者其他依赖

    http://www.cnblogs.com/couhujia/archive/2009/09/22/1572016.html

    <%@ OutputCache Duration="3600" VaryByParam="None" SqlDependency= "Northwind:Products;Northwind:Categories" %>

    Or u can use the SqlCacheDependency class. It's more simplier as SqlDependency. Here is an example:
    SqlCacheDependency dependency = new SqlCacheDependency(comm);
    int expire = 3;
    DateTime exp = DateTime.Now.AddMinutes(expire);

    Response.Cache.SetCacheability(HttpCacheability.Public);
    Response.Cache.SetExpires(exp);
    Response.Cache.SetValidUntilExpires(true);
    Response.AddCacheDependency(dependency);

    The main defferent between this and Page Fragemant Cache is that:
    - If you use SqlCacheDependency, the server watch only those datas, which is in your query result
    - But if u use Outputcache directive or the SqlDataSource sqldependency attribute, the sql server watch all changes in the table!!!

    http://forums.asp.net/t/991603.aspx

    SqlCacheDependency
    配置文件中的配置
    <system.web>
    <caching>
    <sqlCacheDependency enabled="true" pollTime="轮询时间(毫秒)">
    <databases>
    <add name="名字" connectionStringName="连接字符串的名字" />
    </databases>
    </sqlCacheDependency>
    <!-- 如果是SqlServer2005的话,则只需如下设置,因为SqlServer支持基于通知的缓存失效
    <sqlCacheDependency enabled="true" />
    -->
    </caching>
    </system.web>
    如果不是SqlServer2005的话,应该使用aspnet_regsql注册一下
    aspnet_regsql.exe -S "server" -E -d "database" -ed
    aspnet_regsql.exe -S "server" -E -d "database" -et -t "table"
    如果是Sql验证的话要把-E换成,-U(用户名),-P(密码)

    http://geekswithblogs.net/chrishan/archive/2007/01/11/103370.aspx

    http://hi.baidu.com/wjinbd/blog/item/69a49694b16b2a41d1135eaf.html

    http://www.wangchao.net.cn/bbsdetail_567751.html

    http://www.fly010.net/new1805.html

  • 相关阅读:
    Linux下配置APUE的编译 报错之后如何处理
    Sed命令的使用详细解释
    Linux下安装xrdp
    CentOS7.1 VNC Server服务配置
    Linux下core文件调试方法
    GDB获取帮助信息
    gdb调试工具学习
    Linux中tftp安装及使用笔记
    CentOS7.3安装Python3.6
    C#语言注释详解
  • 原文地址:https://www.cnblogs.com/emanlee/p/1660494.html
Copyright © 2020-2023  润新知