读书人

Sql缓存委以

发布时间: 2012-07-20 10:38:30 作者: rapoo

Sql缓存依赖
Sql缓存依赖主要分为两种:

1.轮询模式(poll model)

2.推模式(push model)

今天先讲解第一种模式:轮询

要使用sql轮询模式,得做三方面的工作:

1.对数据库启用缓存依赖

2.对一个或多个表启用缓存依赖

3.在web.config中配置应用程序

一.对数据启用缓存依赖

在visual studio command prompt中执行以下命令

aspnet_regsql -C "Data Souce=localhost;Integrated Security=True;Initial Catalog=SqlTest" -ed

注释:aspnet_regsql是命令行工具 本命令表示启用SqlTest数据库缓存依赖

Sql缓存委以

当执行该命令后,将会在数据库SqlTest中创建表:AspNet_SqlCacheTablesForChangeNotification,如图:

Sql缓存委以

tableName:记录被缓存的表

notificationCreated:记录缓存被创建的时间

changeId:计数器,当表数据修改后,自动增加1

同事创建5个存储过程:

AspNet_SqlCachePollingStoredProcedure

AspNet_SqlCacheQueryRegisteredTablesStoredProcedure

AspNet_SqlCacheRegisterTableStoredProcedure

AspNet_SqlCacheUnRegisterTableStoredProcedure

AspNet_SqlCacheUpdateChangeIdStoredProcedure

二.对数据表启用缓存依赖

在visual studio command prompt中执行以下命令

aspnet_regsql -C "Data Souce=localhost;Integrated Security=True;Initial Catalog=Pubs" -et -t Customers

注释:对Customers表启用缓存依赖

Sql缓存委以

当执行该命令后,将在数据库表AspNet_SqlCacheTablesForChangeNotification中添加一条记录,如图:

Sql缓存委以

三.配置应用程序