Download SysCache with Sql Dependencies Configuration

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Microsoft Access wikipedia , lookup

Oracle Database wikipedia , lookup

Database wikipedia , lookup

Entity–attribute–value model wikipedia , lookup

Ingres (database) wikipedia , lookup

Microsoft Jet Database Engine wikipedia , lookup

Extensible Storage Engine wikipedia , lookup

Clusterpoint wikipedia , lookup

Open Database Connectivity wikipedia , lookup

Relational model wikipedia , lookup

SQL wikipedia , lookup

Database model wikipedia , lookup

Microsoft SQL Server wikipedia , lookup

PL/SQL wikipedia , lookup

Transcript
SysCache with Sql Dependencies Configuration
SysCache with Sql Dependencies can use SqlCacheDependencies to invalidate cache regions when
data in an underlying SQL Server table or query changes. Query dependencies are only available for
SQL Server 2005. To use the cache provider, the application must be setup and configured to
support SQL notifications as described in the MSDN documentation.
Table Based Dependency
A table based dependency will monitor the data in a database table for changes. Table based
dependencies are generally used for a SQL Server 2000 database but will work with SQL Server 2005
as well. Before you can use SQL Server cache invalidation with table based dependencies, you need
to enable notifications for the database. This task is performed with the aspnet_regsql command.
With table based notifications, the application will poll the database for changes at a predefined
interval. A cache region will not be invalidated immediately when data in the table changes. The
cache will be invalidated the next time the application polls the database for changes. To configure
the data in a cache region to be invalidated when data in an underlying table is changed, a cache
region must be configured in the application’s configuration file. See the sample below.
<sysCache>
<cacheRegion name="Product">
<dependencies>
<tables>
<add name="price"
databaseEntryName="Default"
tableName="VideoTitle" />
</tables>
</dependencies>
</cacheRegion>
</sysCache>
Table Configuration Properties
Property Name
name
tableName
databaseEntryName
Purpose
Unique name for the dependency
The name of the database table that the
dependency is associated with. The table must
be enabled for notification support with the
AspNet_SqlCacheRegisterTableStoredProcedure
The name of a database defined in the
databases Element for sqlCacheDependency for
caching (ASP.NET Settings Schema) element of
the application's Web.config file.
Command Based Dependencies
A command based dependency will use a SQL command to identify records to monitor for data
changes. Command based dependencies work only with Sql Server 2005 databases. Before you can
use SQL Server cache invalidation with command based dependencies, you need to enable the
Service Broker for query notifications. The application must also start the listener for receiving
change notifications from SQL Server. With command based notifications, SQL Server will notify the
application when the data of a record returned in the results of a SQL query has changed. Note that
a change will be indicated if the data in any of the columns of a record change, not just the columns
returned by a query. The query is a way to limit the number of records monitored for changes, not
the columns. As soon as data in one of the records is modified, the data in the cache region will be
invalidated immediately. To configure the data in a cache region to be invalidated based on a SQL
command, a cache region must be configured in the application’s configuration file. See the samples
below.
Stored Procedure
<cacheRegion name="Product" priority="High" >
<dependencies>
<commands>
<add name="price"
command="ActiveProductsStoredProcedure"
isStoredProcedure="true"/>
</commands>
</dependencies>
</cacheRegion>
Select Statement
<cacheRegion name="Product" priority="High" >
<dependencies>
<commands>
<add name="price"
command="Select VideoTitleId from dbo.VideoTitle where Active = 1"
connectionName="default"
connectionStringProviderType="NHibernateExtensions.Caches.SysCache.
ConfigConnectionStringProvider, NHibernateExtensions.Caches.SysCache"/>
</commands>
</dependencies>
</cacheRegion>
Command Configuration Properties
Property Name
Purpose
name
Unique name for the dependency
command
Sql command that returns results which should be
monitored for data changes
isStoredProcedure
Indicates if command is a stored procedure. The
default is false.
connectionName
The name of the connection in the applications
configuration file to use for registering the cache
dependency for change notifications. If no value is
supplied for connectionName or
connectionStringProviderType, the connection
properties from the NHibernate configruation will be
used.
connectionStringProviderType IConnectionStringProvider to use for retrieving the
connection string to use for registering the cache
dependency for change notifications. If no value is
supplied for connectionName, the unnamed
connection supplied by the provider will be used.
IsRequired
true
false
false
false
Aggregate Dependencies
Multiple cache dependencies can be specified. If any of the dependencies triggers a change
notification, the data in the cache region will be invalidated. See the samples below.
Multiple commands
<cacheRegion name="Product">
<dependencies>
<commands>
<add name="price"
command="ActiveProductsStoredProcedure"
isStoredProcedure="true"/>
<add name="quantity"
command="Select quantityAvailable from dbo.VideoAvailability"/>
</commands>
</dependencies>
</cacheRegion>
Mixed
<cacheRegion name="Product">
<dependencies>
<commands>
<add name="price"
command="ActiveProductsStoredProcedure"
isStoredProcedure="true"/>
</commands>
<tables>
<add name="quantity"
databaseEntryName="Default"
tableName=" VideoAvailability" />
</tables>
</dependencies>
</cacheRegion>
Additional Settings
Data dependencies do not have to be specified for the cache regions. Time based expiration policies
can be specified if no data dependencies are specified. If time based expiration policies are specified
and data dependencies are specified, the time based expiration policies will be ignored. See the
sample below.
Relative expiration
<cacheRegion name="Product" relativeExpiration="300" priority="High" />
Time of Day Expiration
<cacheRegion name="Product" timeOfDayExpiration="2:00:00" priority="High" />
Additional Configuration Properties
Property Name
relativeExpiration
Purpose
Number of seconds that an individual item will
exist in the cache before being removed. Only
valid if no dependencies are specified.
timeOfDayExpiration
priority
24 hour based time of day that an item will exist
in the cache until. 12am is specified as
00:00:00. 10pm is specified as 22:00:00. Only
valid if relativeExpiration and no dependencies
are specified.
System.Web.Caching.CacheItemPriority that
identifies the relative priority of items stored in
the cache.