Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
ASP .NET 2.0 Beta Preview - B. Evjen.pdf
Скачиваний:
26
Добавлен:
24.05.2014
Размер:
15.33 Mб
Скачать

SQL Cache Invalidation

From this command prompt, you can see that I simply enabled the Northwind database (the sample database that comes with SQL Server) for SQL cache invalidation. The aspnet_sqlcache.exe tool responded as follows:

Enabling the database for SQL cache dependency.

Finished.

Now that you have enabled the database for SQL cache invalidation, you can enable one or more tables contained within the Northwind database.

Enabling tables for SQL Server cache invalidation

You enable one or more tables by using the following command:

aspnet_regsqlcache.exe –S localhost –U sa –P password –d Northwind –t Customers –et

You can see that this command is not much different from the one for enabling the database, except for the extra –t Customers entry. Customers is the name of the table that is enabled, as shown in Figure 11-3.

Figure 11-3

In this screen shot, you can see that I enabled two tables within the Northwind database. The first is the Customers table and the second is the Products table. After a table is successfully enabled, you receive the following response:

Enabling the table for SQL cache dependency.

Finished.

After the table is enabled, you can begin using the SQL cache invalidation features. But before you do, the following section shows you what happens to SQL Server when you enable these features.

Looking at SQL Server

Now that both the Northwind database and the Customers and Products tables have been enabled for SQL cache invalidation, look at what happens in SQL Server to enable this. If you open up the SQL Server Enterprise Manager, you see a new table contained within the Northwind database —

AspNet_SqlCacheTablesForChangeNotification (whew, that’s a long one!). You should see what is shown in Figure 11-4.

327

Chapter 11

Figure 11-4

At the top of the list of tables in the right-hand pane, you see the AspNet_SqlCacheTablesFor ChangeNotification table. This is the table that ASP.NET uses to learn which tables are being monitored for change notification and also to make note of any changes to the tables being monitored. The table is actually quite simple when you look at the details, as illustrated in Figure 11-5.

Figure 11-5

From this screen shot, you can see three columns in this new table. The first is the tableName column. This column is simply a String reference to the name of the table contained in the same database. Any table named here is enabled for SQL cache invalidation. Therefore, Figure 11-5 shows that the Customers and Products table are enabled.

The second column, notificationCreated, shows the date and time when the table was enabled for SQL cache invalidation. The final column, changeId, is used to communicate to ASP.NET any changes to the included tables. ASP.NET is monitoring this column for changes and, depending on the value, either uses what is stored in memory or makes a new database query.

328

SQL Cache Invalidation

Looking at the tables that are enabled

Using the aspnet_regsqlcache.exe tool, you can see which tables are enabled in a particular database with a simple command. If you are working through the preceding examples, you see that so far you have enabled the Customers and Products tables of the Northwind database. To get a list of the tables that are enabled, use something similar to the following command:

aspnet_regsqlcache.exe –S localhost –U sa –P password –d Northwind –lt

This command produces the results shown in Figure 11-6.

Figure 11-6

As you can see from this screen shot, the -lt command produces a simple list of tables enabled for SQL cache invalidation. Inputting this command produces the following results:

Listing all tables enabled for SQL cache dependency:

Customers

Products

Disabling a table for SQL Server cache invalidation

Now that you know how to enable your SQL Server database for SQL Server cache invalidation, take a look at how you remove the capability for a specific table to be monitored for this process. To remove a table from the SQL Server cache invalidation process, use the –dt command. Figure 11-7 details how to remove an individual table from the process.

Figure 11-7

329

Chapter 11

From Figure 11-7, you can see that the tables enabled for SQL Server cache invalidation are listed using the –lt command. It shows that you have both the Customers and Products tables enabled. Next, you remove the Products table from the process using the following command:

aspnet_regsqlcache.exe –S localhost –U sa –P password –d Northwind –t Products -dt

You can see that all you do is specify the name of the table using the –t command followed by a –dt command (disable table). From the figure, you can also see the third command again lists the tables that are enabled for SQL Server cache invalidation, and this time, the Products table is not listed — instead, only the Customers table is listed.

Disabling a database for SQL Server cache invalidation

Not only can you pick and choose the tables that you want to remove from the process, but you can also disable the entire database for SQL Server cache invalidation. In order to disable an entire database, you use the –dd command (disable database). You should note that disabling an entire database for SQL Server cache invalidation also means that every single table contained within this database is also disabled. Figure 11-8 shows the Northwind database being disabled on my computer.

Figure 11-8

From this figure, you can see that I disabled the Northwind database from SQL Server cache invalidation using the –dd command. This is the result:

Disabling the database for SQL cache dependency.

Finished.

To ensure that the table was no longer enabled for SQL Server cache invalidation, I attempted to list the tables that were enabled for cache invalidation using the –lt command. I received the following error:

An error has happened. Details of the exception:

The database is not enabled for SQL cache notification. To enable a database for SQL cache notification, please use SQLCacheDependencyAdmin.EnableNotifications method, or the command line tool aspnet_regsql.exe.

If you now open the Northwind database in the SQL Server Enterprise Manager, notice that the

AspNet_SqlCacheTablesForChangeNotification table has been removed for the database.

330