惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Blog — PlanetScale
Blog — PlanetScale
B
Blog
A
About on SuperTechFans
大猫的无限游戏
大猫的无限游戏
爱范儿
爱范儿
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
H
Help Net Security
H
Hackread – Cybersecurity News, Data Breaches, AI and More
博客园 - 三生石上(FineUI控件)
有赞技术团队
有赞技术团队
酷 壳 – CoolShell
酷 壳 – CoolShell
WordPress大学
WordPress大学
IT之家
IT之家
D
Docker
Google DeepMind News
Google DeepMind News
罗磊的独立博客
T
The Blog of Author Tim Ferriss
aimingoo的专栏
aimingoo的专栏
博客园 - 叶小钗
Recent Announcements
Recent Announcements
阮一峰的网络日志
阮一峰的网络日志
D
DataBreaches.Net
博客园 - 司徒正美
Engineering at Meta
Engineering at Meta

博客园 - Jun1st

Application之间共享Master Page ASP.NET AJAX 4的Client-Side Template和DataView ASP.NET AJAX 4的Client-Side Template和DataView 体验ASP.NET4之ClientID 体验ASP.NET 4之URL Routing 使用Extension Methods来使IDataReader更加方便 Custom WCF Configuration File USE HttpRuntime.Cache OVER HttpContext.Current.Cache Make Asynchronous Calls from Page IIS and VS Embedded Local Web Server Integrate jQuery with ASP.NET Data Controls Tech-Ed 2008 上海 ASP.NET MVC的分页和导航 LINQ and Pipeline Pattern Why Would a .Net Programmer Learn Ruby On Rails(翻译) ASP.NET MVC之AJAX Asp.Net MVC---Walkthrough Asp.Net MVC 入门篇——Overview Security Basics and ASP.NET Support(翻译)
Asp.Net 2.0之SqlCacheDependency
Jun1st · 2008-03-14 · via 博客园 - Jun1st

2008-03-14 01:09  Jun1st  阅读(1525)  评论()    收藏  举报

Introduction

ASP.NET 2.0提供了一些新的用于提升程序性能的技术特性,其中,缓存技术是非常重要的一个特性,它提供了一种非常好的本地数据缓存机制,可以非常容易的定制属于数据缓从,从而有效的提高数据访问的性能。本文将介绍一下SqlCacheDenendency.

1. Page&Source Code

为了简单起见,示例就是用Sql Server的Sample数据库。新建一个Asp.net 2.0或者3.0,3.5的Web site之后,在一个web form上,添加一个GridView, 并配置一个SqlDataSource, 适当的选择几个column,如图:

注意:需要设置SqlDataSource的EnableCaching属性为true,才能实现Cache。除此之外,还需要设置SqlCacheDependency为:Northwind:Employees,如果有多个数据库表要实现这种dependency, 多个表之间以分号分隔。

2.配置文件

<system.web>这个config节点之间需要加上如下配置代码:

<caching>

<sqlCacheDependency enabled="true">

<databases>

<add name="Northwind" connectionStringName="NorthwindConnectionString" pollTime="1000"/>

</databases>

</sqlCacheDependency>

</caching>

使用的connectionStringName为任何一个可以连接到所用数据库的连接。pollTime为轮训更新的时间间隔,为了测试方便,把pollTime设置为1000。

3.启用数据库的SqlCacheDependency

使用如下命令行启用数据库的CacheDependency属性:

    aspnet_regsql -E -ed -d Northwind -et -t Employees

-E:表示使用Windows集成验证。

4.测试

先run application,显示数据,再更改一下数据库数据,再刷新一下页面,就可以看到更新的数据了。

Summary

比较简单,呵呵,请"园友"们多多指教。