11-httpcontentprovider access cache of ASP. NET Enterprise Development Framework isline framework Series

Source: Internet
Author: User
Tags microsoft sql server 2005

Today we will introduce the namespace of isline. httpcontent. httpcontentprovider:

This provider encapsulates operations on cache, session, and cooike. There are three main classes in this space: cookieprovider, sessionprovider, and cacheprovider.

Constraints

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:

 

Code

  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.

Cacheprovider class

First, let's take a look at the 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 caches all web and non-WebProgramCan be called, while httpcontext can only be used in the web.

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:

Expiration type

Description

Sliding Window

Specifies how long an item expires after the last access.

Absolutely expired

Specify 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:

Description

File dependency

Items in the cache depend on external files. If the file is modified or deleted, the cache item is also removed.

SQL dependency

Items in the cache depend on changes 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.

 

Use the method in cacheprovider

Method

Description

Cacheprovider ()

Constructor

Cacheprovider (string cachename)

Constructor. The parameter specifies the name of the cache to be operated.

Cacheprovider (cachetype usecachetype, string cachename, cachedependencytype CDT, object depend)

Constructor. 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, it can be an SQL statement or a file;

Depend is a specific dependency.

Object getcontent ()

Get default cache content

Object getcontent (string name)

Obtain the cache content. The parameter specifies the name of the cache to be operated.

Bool updatecontent (Object O)

Update or create default cache content

Bool updatecontent (string name, object O)

Updates or creates cache content. The parameter specifies the name of the cache to be operated.

Bool remove ()

Remove Default Cache

Bool remove (string name)

Removes the cache. The parameter specifies the name of the cache to be operated.

Bool isexit ()

Determine whether the default cache exists

Bool isexit (string name)

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. isline. httpcontent. hcdatatypeenum namespace:

 

Code

  Namespace  Isline. httpcontent. hcdatatypeenum

{

Public Enum Datetype

{

Days,

Hours,

Years,

Minutes

}


Public Enum Cachetype

{

Httpruntime,

Httpcontext

}



Public Enum Cachedependencytype

{

SQL,

File,

None

}



Public Enum Removetype

{

Removeinput,

Removeallexcludeinput

}

}

 

 

Note that even if cacheprovider (string cachename) is used to specify the cache to be operatedCodeThe method called by the instance contains the names of other caches. When you use a method without the cache name parameter, the new cache will be operated, the cache specified in the constructor is ignored.

For example:

  Cacheprovider CP= NewCacheprovider ("");

CP. getcontent ();//In this step, the content of cache "A" will be obtained.

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"

 

I amLi MingWelcome to my next articleArticle.

 Isline framework is an open-source enterprise-level system development framework. It currently has the following series:

 

One of the isline framework series-the first intimate contact

Isline framework Series II-namespaces and contracts

Isline framework Series 3-Seven Weapons

Isline framework Series 4-dataprovider Data Access (I)

Isline framework Series 5-dataprovider Data Access (medium)

Isline framework Series 6-dataprovider Data Access (lower)

Seven isline framework series -- applogprovider log framework (II)

Octal of isline framework series -- exceptionprocessprovider exception framework (I)

Isline framework Series 9-exceptionprocessprovider exception framework (II)

Ten isline framework series -- httpcontentprovider access Cache

 

 

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.