Cache cache uses

xiaoxiao2021-03-06  42

I. Instructions for use

Cache.Insert (String, Object, Cached, CacheItemPriority, CacheItemRemovedCallback)

parameter

Key

The cache key used to reference the object.

Value

To insert an object in the cache.

Dependencies

The file dependency or cache key dependency of this item is dependent. This object is invalid when any dependency changes, and is removed from the cache. If there is no dependency, this parameter contains a space reference (Nothing in Visual Basic).

AbsoluteExpiration

The inserted object will expire and be removed from the cache.

SLIDINGEXPIRATION

The time interval between the last visit to the object expires when the object is inserted. If this value is equivalent to 20 minutes, the object will be removed and removed from the cache after the last time was accessed 20 minutes.

Priority

The object is represented by the CacheItemPriority enumeration relative to the cost of other items stored in the cache. This value is used when there is an exit object; the object having a lower cost is removed from the cache before having a higher cost object.

OnremoveCallback

The delegate (if provided) will be called when the object is removed from the cache. When you delete an object from the cache, you can use it to notify the application.

2. This method will override existing cache items with the same Key parameters

Pay attention

Key or

The Value parameter is empty, and ArgumentNullexception occurs. If they will

SlidingExpiration parameter is set to be less than

TimeSpan.zero or greater than one year, argumentOutofrangeException occurs. You cannot simultaneously set up to the same cache item to adjust the expiration and absolute expiration time. If this is done, argumentException will occur.

Third. Coke cleaning, expire, file-dependent and key dependencies

Cleaning is that when the memory becomes very small, the cache is trying to remove uncommon usage and less important items. Programmers who want to control how to occur how to occur can provide prompts for the cleaning program when they are inserted into the cache, pointing out the relative cost of the creation and enables the item to be useful and must have a relative access rate. The extension allows the programmer to provide a cache term, and its time can be exact time (for example, 6: 00 expiration), or the last time for the last use of the item (for example, 20 minutes after the last access item) Expire). After the item expires, it will be removed from the cache. If you try to retrieve it, return null values ​​unless you reinsert the cache. Files and key dependencies allow the validity of the cache items based on external files or other cache items. If the dependency changes, the cache item is faded and removed from the cache. For examples of how to use this feature, consider the following scenario: The application reads financial information from the periodically updated XML file. The application handles the data in the file and creates object graphics indicating the data in the available format. The application caches the data and inserts a dependency on the file that is read from it. When this file is updated, the data is removed from the cache, and the application can re-read it and reinsert the update copy of the data. Four .cachedependency class

Tracking cache dependencies, caching dependencies can be files, directories, or keys in the application's cache. Unable to inherit this class.

For a list of all members of this type, see Cachedependency members.

System.Object System.Web.Caching.cachedependency

[Visual Basic] Notinheritable Public Class Cached Assency IMPLEments Idisposable

[C #] public sealed class cachedependency: idisposable [c ] public __gc __sealed class cachedpendency: public idisposable

[JScript] Public Class Cached Assency Implements Idisposable

Thread security

All public static (Visual Basic) members are safe for multithreading operations. But not to ensure that any instance member is thread safe.

Note

You can add an item with dependencies to the application cache with the add and INSERT methods.

When an application is added to the application's cache object, an instance of the CacheDependency class will automatically create an instance of the CacheDependency class to track changes to the specified file, key, or directory. This helps to avoid changing the object when creating an object and inserting it into Cache. The Cachedependency instance can represent a single file or directory, a set of files or directories, or a set of files or directories with a series of cache keys (these cache keys indicate other items stored in the Cache object).

Example

[Visual Basic, C #] The following example shows how to use the HaschangeD property to determine if the CacheDependence has changed after the previous request of a certain item in Cache. Set the DT value of the incoming START parameter to datetime.now.

[Visual Basic] 'INSERT The Cache Item. DIM DEP AS NEW

Cachedependency (FileName, DT) Mycache.insert ("Key", "Value", DEP)

Check WHETHER CACHEDEPENDENCY.HASCHANGED IS TRUE. IF dep.haschanged

Then Response.write ("

") Else Response.write ("

The Dependency Has Not Changd. ") End IF

[C #] // INSERT The cache item. CachedPendency Dep = New Cached Cachedependency (FileName, DT);

Cache.Insert ("Key", "Value", DEP);

// Check WHETHER CACHEDEPENDENCY.HASCHANGED IS TRUE. IF (dep.haschanged) Response.write ("

"); Else Response.write ("

The Dependency Has Not Changed. ");

转载请注明原文地址:https://www.9cbs.com/read-52609.html

New Post(0)