一、SQL SERVER 7.0/2000和SQL SERVER 2005的简介及比较 1.1 SQL SERVER 7.0/2000 SQL SERVER 7.0/2000没有提供内置的支持数据缓存依赖的功能,所以只能通过采用添加特定数据库表、触发器等方式,通过后台不断轮询数据库来检查数据更改。当在数据表上执行INS
一、SQL SERVER 7.0/2000和SQL SERVER 2005的简介及比较
1.1 SQL SERVER 7.0/2000
SQL SERVER 7.0/2000没有提供内置的支持数据缓存依赖的功能,所以只能通过采用添加特定数据库表、触发器等方式,通过后台不断轮询数据库来检查数据更改。当在数据表上执行INSERT、UPDATE、 DELETE操作时将自动发出更改通知,所以只能监测到表级,具体到哪一行是没法跟踪的。
使用方法步骤:
1.1.1 使用aspnet_regsql命令行或SqlCacheDependencyAdmin来配置连接数据库。
1.1.1.1 ALTER DATABASE
aspnet_regsql -S
aspnet_regsql -S 1.1.1.2 SqlCacheDependencyAdmin.EnableNotifications(connectionString); //启动数据库的数据缓存依赖功能 SqlCacheDependencyAdmin.EnableTableForNotifications(connectionString, table); //启用数据表缓存 推荐这段代码写在Global.asax的Application_Start方法中,以便应用程序启动的时候就启用数据库和数据表的缓存依赖功能。 SqlCacheDependency scd = new SqlCacheDependency("数据库名称","表名"); Cache.Insert(...,scd,...); 内置支持SQL数据缓存依赖,内置通知传递服务,能够提供更小粒度的数据更改监测,使用和配置简单。 使用方法步骤: 1.2.1 检测是否已经启用Service Broker 这个地方我看有些朋友翻译的成“是否能启用”,这是不对的,这里我把英文原文帖出来:“This can be checked by calling "Select databasepropertyex('db Name', 'IsBrokerEnabled')". A '1' means that the broker is enabled. A '0' means that the broker is not enabled. ”。 依据我的经验,如果直接在当前SqlServer2005上新建一个数据库的话,默认是打开的,如果是从其他地方数据库导过来的,导入之后默认关闭了。(可能有不准确,大家可以自己试验一下测试一下)。如果已经打开可直接调到1.2.2。 1.2.1.1 启用Service Broker ALTER DATABASE 数据库名称 SET ENABLE_BROKER; 1.2.2 在实现基于服务的SQL数据缓存依赖过程中,需要显式调用SqlDependency.Start来启动接受依赖项更改通知的侦听器。 SqlDependency.Start(connectionString); //推荐将这段代码加到Global.asax的Application_Start方法中, 1.2.3 应用程序数据缓存中使用 SqlCommand cmd = new SqlCommand(sql,conn); SqlCacheDependency scd = new SqlCacheDependency(cmd); Cache.Insert(...,scd,...); 注意: a). 必须设置完全限定名称的数据表。即表名前面需要加所有者,如dbo.test。 b). 必须明确设置所访问数据库列名称,不能使用“*”。 c). 必须保证不是聚合函数。如COUNT、MAX等。 a). 使用SQL SERVER 2005 时,SqlCacheDependency类支持与System.Data.SqlClient.SqlDependency类进行集成。应用程序可创建SqlDependency对象,并通过OnChanged事件处理程序接受通知进行注册。这样,应用程序不仅可以使用Sql server 2005的查询通知机制来监测使用SQL查询结果无效的数据更改,并将缓存对象从缓存中移除,而且还可以轻松获取数据更改通知,以便刷新缓存。(从这里可以看出,当触发onRemoveCallback委托的时候,数据已经从缓存里面删除了,这样一来可以手动在委托里面添加缓存,或者干脆设置成null,让他下次调用的时候再缓存。) b). 不仅向应用程序添加缓存依赖项,还可以与@OutputCache指令一起使用,以生成依赖于SqlServer数据库表的输出缓存的页面或用户控件。对于用户控件,@OutputCache指令不支持使用SQL SERVER 2005 的查询通知(即onRemoveCallback委托)。 二、System.Web.Caching.Cache Insert和Add区别 object Add(string key, object value, CacheDependency dependencies, DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority priority, CacheItemRemovedCallback onRemoveCallback); void Insert(string key, object value); a). Insert方法支持5种重载,使用灵活,而Add方法必须提供7个参数; b). Add方法可以返回缓存项的数据对象,Insert 返回Void; c). 添加重复缓存情况下,Insert会替换该项,而Add方法会报错。 三、 CacheDependency、AggregateCacheDependency、SqlCacheDependency 3.1 CacheDependency是AggregateCacheDependency和SqlCacheDependency的父类。主要用于在应用程序数据缓存对象与文件、缓存键、文件或缓存键的数组或另外一个CacheDependency对象之间建立依赖关系。CacheDependency监视依赖关系比便在任何对象更改时自动移除缓存对象。CacheDependency可以监测一组(到文件或目录的)文件路径的更改情况。 3.2 AggregateCacheDependency主要用于实现聚合缓存依赖。如一笔数据同时对两个表进行缓存依赖,一旦其中任何一个表数据更改缓存将失效。 SqlCacheDependency (SqlCommand) 用于SQL SERVER 2005 SqlCacheDependency (数据库名, 表名) 用于SQL SERVER 7.0/2000 补充 注意修改Web.config连接数据库的代码和Global.asax中对应SQL2000和2005不同的启动缓存代码! www.shenjk.comhttp://www.shenjk.com/details/700.html -et 启动数据表的数据缓存依赖功能
1.1.2 配置Web.config
1.1.3 应用程序数据缓存中使用(还可以在数据源控件、输出缓存整个页面时使用,这里就不介绍了,下同)
1.2 SQL SERVER 2005
Select DATABASEpRoPERTYEX('数据库名称','IsBrokerEnabled') -- 1 表示已经启用 0 表示没有启用
2009-5-26补充: 如果执行此语句超过10秒或处于假死状态,请重启数据库,什么都别做先执行这个语句就行了!
SqlDependency.Stop(connectionString); //用于关闭,可加在Global.asax的Application_End方法中。
1.3 比较、区别
SQL SERVER 7.0/2000
SQL SERVER 2005
实现机制
轮询
通知传递服务(Service Broker)
是否需要配置启用
需要
不需要,内置支持
数据更改检测
限于表级更改监测
表级、行级更改监测
并且很明显,SQL SERVER 2005的缓存机制更加高效。另外,SqlCacheDependency类还特别结合SQL SERVER 2005 进行了优化:
2.1 Add方法
2.2 Insert方法
void Insert(string key, object value, CacheDependency dependencies);
void Insert(string key, object value, CacheDependency dependencies, DateTime absoluteExpiration, TimeSpan slidingExpiration);
void Insert(string key, object value, CacheDependency dependencies, DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemUpdateCallback onUpdateCallback);
void Insert(string key, object value, CacheDependency dependencies, DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority priority, CacheItemRemovedCallback onRemoveCallback);
2.3 比较、区别
3.3 SqlCacheDependency将应用程序数据缓存对象、页面输出缓存、数据源控件等与指定SQL Server数据库表或Sql Server 2005 查询结果之间建立缓存依赖关系,在表发生更改(Sql Server 2005 行级别更改)时,自动从缓存中删除和重新添加与该表关联的缓存对象。一般而言:
1. 2009-5-26 范例:缓存依赖范例 源代码

InnoDBBufferPool reduces disk I/O by caching data and indexing pages, improving database performance. Its working principle includes: 1. Data reading: Read data from BufferPool; 2. Data writing: After modifying the data, write to BufferPool and refresh it to disk regularly; 3. Cache management: Use the LRU algorithm to manage cache pages; 4. Reading mechanism: Load adjacent data pages in advance. By sizing the BufferPool and using multiple instances, database performance can be optimized.

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

MySQL is worth learning because it is a powerful open source database management system suitable for data storage, management and analysis. 1) MySQL is a relational database that uses SQL to operate data and is suitable for structured data management. 2) The SQL language is the key to interacting with MySQL and supports CRUD operations. 3) The working principle of MySQL includes client/server architecture, storage engine and query optimizer. 4) Basic usage includes creating databases and tables, and advanced usage involves joining tables using JOIN. 5) Common errors include syntax errors and permission issues, and debugging skills include checking syntax and using EXPLAIN commands. 6) Performance optimization involves the use of indexes, optimization of SQL statements and regular maintenance of databases.

MySQL is suitable for beginners to learn database skills. 1. Install MySQL server and client tools. 2. Understand basic SQL queries, such as SELECT. 3. Master data operations: create tables, insert, update, and delete data. 4. Learn advanced skills: subquery and window functions. 5. Debugging and optimization: Check syntax, use indexes, avoid SELECT*, and use LIMIT.

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.

MySQL is an open source relational database management system that is widely used in Web development. Its key features include: 1. Supports multiple storage engines, such as InnoDB and MyISAM, suitable for different scenarios; 2. Provides master-slave replication functions to facilitate load balancing and data backup; 3. Improve query efficiency through query optimization and index use.

SQL is used to interact with MySQL database to realize data addition, deletion, modification, inspection and database design. 1) SQL performs data operations through SELECT, INSERT, UPDATE, DELETE statements; 2) Use CREATE, ALTER, DROP statements for database design and management; 3) Complex queries and data analysis are implemented through SQL to improve business decision-making efficiency.

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

WebStorm Mac version
Useful JavaScript development tools

Atom editor mac version download
The most popular open source editor

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software