SqlConnection (Strcon)){SqlCommand comm = new SqlCommand (strSQL, conn);SqlDependency SQLDEP = new SqlDependency (comm);Sqldep.onchange + = Sqldep_onchange;IF (Conn. state = = connectionstate.closed) Conn. Open ();Comm. ExecuteNonQuery ();}}catch (Exception ex){Logutility.add (ex);}}The above method is to tell the database, when you specify the table data changes, to move out of the cacheWe can now add the
Asp.net page SqlCacheDependency cache instance,
Cache Technology is a very practical technology in asp.net programming, and is also a common technology in large-scale web programming. This article describes this in the form of an instance. The details are as follows:
SqlCacheDependency SQL cache on the asp.net page:
The Cahce/SqlCachePage. aspx page code is as follows:
SQL cache of the data source control:
The Cahce/SqlCachePage. aspx page code is as follows:
Related configurations in web. con
outputCacheSettings section. If the name does not match the configuration file, an exception is thrown.
NoStore: A boolean value that determines whether to block the second-level storage of sensitive information. Setting this property to true is equivalent to executing the following code during the request: Response. cache. setNoStore (); included in the user control (. the @ OutputCache command in the ascx file does not support this attribute.
Shared: A boolean value to determine whether the
SqlCommand (strSQL, conn);SqlDependency SQLDEP = new SqlDependency (comm);Sqldep.onchange + = Sqldep_onchange;IF (Conn. state = = connectionstate.closed) Conn. Open ();Comm. ExecuteNonQuery ();}}catch (Exception ex){Logutility.add (ex);}}The above method is to tell the database, when you specify the table data changes, to move out of the cacheWe can now add theMyObject obj= httpruntime.cache["CacheName"] a
the target object, you need to create the object through PolicyInjecctor (Remoting PolicyInjection by default. The integration of Unity and PIAB allows Unity Container to create objects.
Unity is built on ObjectBuilder, and ObjectBuilder is the cornerstone of the entire Enterprise Library and other open-source frameworks (such as Smart Client Software Factory) of P P. ObjectBuilder, as its name implies, is a component for object creation. ObjectBuilder creates objects by using Strategy-based o
action Cache. //+//returns:27//The child action cache. public static System.Runtime.Caching.ObjectCache Childactioncache {get; set;}/////SUMMARY:31//Gets or Sets the cache duration, in seconds. +/////RETURNS:34//the cache duration. public int Duration {get; set;}//PNS//summary:38//Gets or sets the Locat Ion. //+//returns:41//the location. OutputCacheLocation location {get; set;}//+//summary:45//Gets O R sets a value that indicates whether to store the cache. */////RETURNS:48//True if the cache
the primary controller cache thenpublic class Studentmanagercontroller:controller{Private Studententities db = new studententities ();[OutputCache (CacheProfile = "Configcache")]Public ActionResult Create (){Viewbag.scclassid = new SelectList (db.scclasslist, "ID", "className");return View ();}} The cache dependency, that is, by configuring the node sqldependency to obtain the associated data base and the table to implement the cache dependency:
protocols to notify caching, if some users outside the application were updated to overwrite read-only tables. This "notification" solution simply notifies the cache that a row has been added or modified, indicating that the cache must be refreshed. How to tell which rows of the cache have changed or which rows have been added has always been a challenge, as is the issue of distributed databases and distributed transactions or merge replication. A LOW-COST notification solution is to flush the
means that the cache information is updated when the data for the table is changed. Mainly used in the Asp.net_regsql.exe, the file is stored in the C:\Windows\Microsoft.NET\Framework\v4.0.30319.Usage: Open the command prompt tool, go to the directory where the Asp.net_regsql.exe is located, execute the commandAspnet_regsql.exe-s Replace the Aspnet_regsql.exe-s. -U sa-p sasa-ed-d test-et-t yhSuccessful opening as5. To add a cached policy for homecontroller action, it is simple to add [OutputCac
specified time based on the index value and then returns it to the client via the JSON data format.
Now that we've implemented the pie chart (dashboard_pie), let's run the index.cshtml page to see how it works!
Fig. 7 Pie chart
We notice that figure 1 is a dynamic diagram that visually shows the trend of stackoverflow popular tags, and if we're going to implement a dynamic data graph, how do we do that?
In fact, the problem is converted to real-time access to data, and then generate a dat
Caching technology is a very practical technique in asp.net programming, and it is a common technique in large web programming. This article explains this in the form of an instance. Specifically as follows:
SqlCacheDependency SQL cache for asp.net pages:
The cahce/sqlcachepage.aspx page code is as follows:
SQL cache for data source control:
The cahce/sqlcachepage.aspx page code is as follows:
Related Configuration in web.config:
Note: for SQL Server 2005
The recent project takes a few seconds to get the data, check the database server pressure is very large, so use caching technology to alleviate the server pressure.Using the SqlCacheDependency polling method to get the cache, SqlDependency query notifications to update the cache should be better, first of all, the way to poll.The configuration file is as follows:where connectionstringname= "conn" is the name of connectionstrings,name= "Msbaby" ,msbab
.
Now we have implemented the pie chart (Dashboard_Pie). Next, let's run the Index. cshtml page to view the running effect!
Figure 7 pie chart
We noticed that figure 1 is a dynamic chart that intuitively shows the trend of Stackoverflow hot labels. How can we achieve dynamic data Graph Generation?
In fact, the problem is converted to real-time data acquisition, and it is OK to generate a Data graph. To achieve real-time data acquisition, we can think of the following methods:
1. Timer ()
2
the data cache to the hard disk, remember to set the value of the duration largerduration= "3600", if the set is too small, the server will be too frequent write data on the hard disk will degrade performance, if in memory cache data duration "" Do not set too long, of course, the specific length of time to everyone to try to know.MVC Page CachingTo implement page caching in an ASP. NET MVC Project, configure the following nodes in Web. config: system.web> Caching> outputcachesettings>
one,. The basics of caching in netTwo types of dependencies are supported in. NET:
CacheDependency
SqlDependency
Indicates a dependency on a file or directory
Represents a dependency on a SQL database
Expiry time
Absolute Expiration Time
Sliding Expiration Time
A specific point in time, type datetime
A time interval with a timespan of type
Priority:
. Configure web pages for the cache function in ASP. NET data cache
﹤%@OutputCacheDuration="3600"SqlDependency="Northind:Employees"VaryByParam="none"%﹥
3. Set the cache configuration for ASP. NET data caching in the Web. config file.
﹤caching﹥
﹤sqlCacheDependencyenabled="true"pollTime="1000"﹥
﹤database﹥
﹤addname="Northind"connectionStringName="..."pollTime="1000"/﹥
﹤/database﹥
﹤/sqlCacheDependency﹥
﹤/caching﹥
The conten
).
Tierdeveloper.
Data expiration
Absolute expiration time.
The idle time expires.
Cache dependency
Keyword-based dependency.
File-based dependency.
Dependencies Based on Multiple cache keywords.
Cache and Database Synchronization
SQL Server 2005-based sqldependency.
The voting-based dbdependency applies to SQL 2000, Oracle oledb.
Clustered-wide Event Notification
Update and dele
Added cache management in Asp.net 2.0:CacheDependency tracks Cache dependencies. Cache dependencies can be files, directories, or keys with other objects in the application's Cache.The SqlCacheDependency class monitors specific SQL Server database tables on all supported SQL Server versions (7.0, 2000,200 5) so that when the table is changed, items associated with the table are automatically deleted from the Cache. When the database table is changed, the Cache items are automatically deleted
, SqlDependency, VaryByControl, VaryByCustom, and VaryByParam. The @ OutputCache instruction string in the page output cache has up to 10 attributes. The preceding problems must be noted when setting the control cache. The following lists some examples of using the @ OutputCache command to set the control cache, with emphasis on Attribute applications such as VaryByParam and VaryByControl.The @ OutputCache command in the user control sets the source c
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.