简体   繁体   中英

How to implement SQLDependency caching in Asp.Net?

HI谁能解释我如何在Asp.Net中实现SQL依赖缓存?

See David Hayden's article on the subject for an example.

Generally you connect the dependency to a command and add the dependency when inserting into the cache.

var command = new SqlCommand("SELECT something FROM dbo.ATable", connection);
var dependency = new SqlCacheDependency(command);
var result = ObtainResultUsingThe(command);

Cache.Insert("CacheKey", result, dependency);

Observe that special rules apply for your queries. Among others:

  • Named columns must be selected (no SELECT *)
  • Must use fully qualified name of table (eg dbo.ATable)

Edit:

For using the dependency in caching an entire page, you can follow this example .

How you implement SQL dependency caching will depend on the version of SQL server you are using. I would suggest reading this MSDN article to get a better understanding of how it hangs together.

hi answer with implementation can be found at below site

http://harismile.wordpress.com/2010/09/09/mvc-with-ef-sqldependencycache/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM