SqlCacheDependency

SqlCacheDependency

Establishes a relationship between an item stored in an application's Cache object and either a row in a specific SQL Server database table or the results of a SQL Server 2005 query.


Constructor

# new SqlCacheDependency(connectionString, cmdText, cmdType, cmdParams)

Initializes a new instance of the SqlCacheDependency class, using the supplied connection string and query string. This constructor is used to create SqlCacheDependency objects that use the query-notification feature of SQL Server 2005 products. SQL query must include the following: Fully qualified table names, including the name of the table owner. For example, to refer to a table called "customers" that is owned by the database owner, the SQL statement must refer to "dbo.customers". Explicit column names in the Select statement. You cannot use the asterisk (*) wildcard character to select all columns from a table. For example, instead of "select * from customers", you must use "select name, address, city, state from dbo.customers".

Parameters:
Name Type Description
connectionString String

connection string to be used by dependency.

cmdText String

cmdText to be used by dependency.

cmdType SqlCommandType

The type of the command. (text/stored procedure)

cmdParams Map

Parameters to be passed to the command.

Example
//Initialize the Cache Cluster 
let cache = await ncache.CacheManager.getCache("demoCache");

 //SQL server configuration
let connectionString = "Data Source=SERVER;Database=temp;User ID=Admin;password = xxxxxxx";

//SQL query 
let queryString = "SELECT ProductID, ProductName, QuantityPerUnit, UnitPrice FROM dbo.PRODUCTS WHERE PRODUCTID = 1";

//Create SqlCacheDependency object
let sqlServerDependency = new ncache.SqlCacheDependency(connectionString, queryString );

// Create CacheItem
let caceItem = new ncache.CacheItem("Value:SqlCacheDependency-test");

//Set dependency of cache item
caceItem.setDependency(sqlServerDependency);
let cacheItemVersion = await cache.add("Key:SqlCacheDependency", caceItem);

Methods

# getCommandParams() → {Map}

Parameters to be used by dependency.

Returns:

Returns Map<String, SqlCmdParams>.

Type
Map

# getCommandText() → {String}

CommandText to be used by dependency.

Returns:

Returns CommandText.

Type
String

# getCommandType() → {CommandType}

Describes the type of the SQL command passed to the SQLDependency.

Returns:

Returns type of the SQL command.

Type
CommandType

# getConnectionString() → {String}

Connection String is the connection string that is required to the cache in order to connect with database.

Returns:

Returns Connection String.

Type
String