Use isline framework to Develop ASP. net programs-use httpcontentprovider to access the cache

Source: Internet
Author: User
Tags microsoft sql server 2005

In the previous issue, I introduced the abnormal display management section. You can use the preset Renderer or custom rendering. Today we will introduce isline. httpcontent. httpcontentprovider namespace, which encapsulates some features in B/S mode, developers can use it to standardize naming issues, obtain unified and standardized access policies (such as Cookie expiration time and SSL support), and develop such policies on the web. if you need to modify the policy later, you can directly update the config file, and the whole site access will change. This provides a unified portal for modifying and controlling site variables, simplifies the modification process, and addsProgramAnd greatly reduces the cost of testing.

This provider encapsulates operations on cache, session, and cooike. There are three main classes in this space: cookieprovider, sessionprovider, and cacheprovider. These three class libraries implement the icapability interface in a unified manner. icapability inherits from the ibasecapability interface. ibasecapability standardizes the basic capabilities of httpcontentprovider, while icapability extends the basic capabilities as follows:

Namespace isline. httpcontent. httpcontentprovider
{
Public interface ibasecapability
{
Bool remove (string name );
Bool isexit (string name );
}
Public interface icapability: ibasecapability
{
Object getcontent (string name );
Bool updatecontent (string name, object value );
}
}

It can be seen that the interface mainly limits how to delete, obtain and update an object, that is, the behavior of session, cookie, and cache. In other providers, there are also specifications related to their own capabilities and operations. These specifications are called conventions or constraints. If you have read this seriesArticleIn the first article, you will be familiar with the introduction of the isline framework protocol.

First of all, we will introduce cache operations, supported by cacheprovider. net two types of cache: runtime cache (httpruntime. cache) and context cache (httpcontext. current. cache). What is the difference between the two types of cache? Here is a simple explanation:

Httpruntime. cache is application-level, while httpcontext. Current. cache is only valid for current web page requests. In other words, httpruntime cache can be called by all web and non-web programs, while httpcontext can only be used in the web. We recommend httpruntime cache for you here. The cache is actually a memory chip. In the classical computer theory, this is a space-for-time approach. Although the memory is cheap at present, improper use may still cause performance problems, because. the. NET runtime environment is hosted, that is, the CLR will manage it when the public language is running. netCodeIf this part of the content is too large, it will also cause performance degradation, because CLR has to maintain a large memory area, and the garbage collection mechanism will be started frequently, this affects the normal running code, which should be avoided.

The data in the cache is easy to lose. The data is not stored in the memory throughout the application lifecycle.. Net manage the cache, which removes the items in the cache when the items expire, are invalid, or the memory is insufficient. You can also configure the application cache to notify the application when an item is removed. Therefore, you do not know when the cache will expire, even if you have configured dependencies.

There are two types of cache Expiration: Sliding Window and absolute expiration. A sliding window is the time that a certain item expires after the last access. Absolute expiration indicates that an item expires at the specified time, regardless of the Access frequency. You can configure the lifetime of one of the cached items to depend on other application elements, such as a file or database. When the element on which the cache item depends is changed, ASP. NET removes the item from the cache.

The cacheprovider class supports the following two types of Dependencies: file dependencies and SQL Server database dependencies. Only items in the cache depend on external files. If the file is modified or deleted, the cache item is also removed; the SQL Server database dependency depends only on the changes made to tables in the Microsoft SQL Server 2005, SQL Server 2000, or SQL Server 7.0 database. For SQL Server 2005, items in the cache can depend on a row in the table.

The following describes the main cacheprovider methods, including overload items, which are listed below:

● Cacheprovider: constructor. The parameter specifies the cache name for the operation.

● Object getcontent: Get the content in the cache. The following parameters are provided. cachetype indicates the cache type, which can be runtime or context cache. The default value is runtime cache; cachename indicates the cache name to be operated. cachedependencytype indicates the dependency type, which can be an SQL statement or a file. Depend indicates a specific dependency. Depend indicates a specific dependency.

● Bool updatecontent: updates or creates cache content. The parameter specifies the cache name to be operated. If no parameter is specified, the system returns the default cached content.

● Bool remove: removes the cache. The parameter specifies the name of the cache to be operated and returns whether the cache is removed successfully.

● Isexit: determines whether the cache exists. The parameter specifies the name of the cache to be operated.

Cache dependencies can be passed in as parameters, which facilitates developers. The SQL cache is only valid for SQL Server databases. You can specify whether to use the file cache or database cache by using the cachedependencytype parameter. cachedependencytype is an enumerated value in isline. httpcontent. in the hcdatatypeenum namespace, the content of the namespace is an enumeration class that standardizes parameter transfer. The four enumeration types are datetype, cachetype, cachedependencytype, and removetype. Datetype standardizes the sliding time types including day, month, year, and minute. cachetype standardizes the cache processing type, including runtime cache and context cache. cachedependencytype standardizes the cache dependency type, including SQL Server database dependency, file dependency, and none. None indicates no dependency. removetype standardizes the operation to remove options. This enumeration will be used in operations on cookies, the two enumerated values removeinput and removeallexcludeinput respectively indicate that the incoming cookie is removed and the cookie other than the incoming cookie is removed.

Note that, even if cacheprovider (string cachename) is used to specify the cache to be operated, if the method called by the instance contains the name of another cache in the code, when you use a method without the cache name parameter in the future, the new cache will be operated, and the cache specified in the constructor will be ignored.

For example:

Cacheprovider CP = new cacheprovider ("");
CP. getcontent (); // This step will get the content of cache ""
CP. isexit ("B") // This step checks whether cache "B" exists
CP. getcontent (); // This step will get the content of cache "B", instead of the cahce "a" in the constructor"

Cache is. NET platform provides a good mechanism for everyone. isline framework encapsulates this mechanism perfectly and provides program personnel with standard naming rules for access to it, it simplifies the Access Call and makes the use process easier.

This article has been published simultaneously in the software report and cannot be reproduced by any personal media.

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.