Today we're going to introduce the IsLine.HttpContent.HttpContentProvider namespace:
This provider mainly encapsulates the operation of caching, session, and Cooike, which has three main classes: Cookieprovider, Sessionprovider, Cacheprovider.
About constraints
These three class libraries unify the Icapability interface, icapability inherit from Ibasecapability interface, ibasecapability standardize the Httpcontentprovider basic ability, And Icapability is an extension of 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 constrains how to delete, obtain and update an object, that is, constraining the session, cookies, cache behavior.
Cacheprovider class
First take a look at the cache operation, Cacheprovider supports. NET two types of cache: Run-time cache (Httpruntime.cache) and Context cache (HttpContext.Current.Cache), What's the difference between these two kinds of cache? Here is a simple explanation:
Httpruntime.cache is application level, and HttpContext.Current.Cache is only valid for current Web page requests. In other words, HttpRuntime cache all Web and non-web programs can be invoked, while HttpContext is only available on the web.
The data in the cache is volatile, the data is not stored in memory throughout the application lifecycle, and the cache is managed by ASP.net, which removes items from the cache when the item expires, is invalid, or is out of memory. You can also configure the application cache to notify the application when an item is removed. So, you don't know when the cache will fail, even if you've already configured the dependencies.
There are 2 types of expiration for caching:
Expiration type |
Description |
Sliding window |
Specifies how long an item has expired since the last time it was accessed. |
Absolute expiration |
Specifies that an item expires at a set time, regardless of the frequency of access. |
You can configure the lifetime of an item in the cache to depend on other application elements, such as a file or database. When an element that is dependent on a cached item changes, ASP.net removes the item from the cache.
The Cacheprovider class supports the following 2 types of dependencies:
|
Description |
File dependencies |
Items in the cache depend on external files. If the file is modified or deleted, the cached item is also removed. |
SQL dependencies |
Items in the cache depend on changes to tables in Microsoft SQL Server 2005, SQL Server 2000, or SQL Server 7.0 databases. For SQL Server 2005, items in the cache can depend on a row in the table. |