Data Cache using ASP. NET Cache

Source: Internet
Author: User

Cache is a set of built-in objects. Is global, similar to static Arraylist. It is thread-safe and does not need to be locked or removed when a project in the Cache is added or modified. Add Cache [Key] = object or Cache. Insert Remove Cache. Remove (key) [How to Use It] first understand the Cache policy. You can call an expiration policy or an absolute expiration policy. Note that the two cannot use the adjustable expiration policy at the same time. You need to set absoluteExpiration = DateTime. maxValue, TimeSpan. fromMinutes (10) configuration items will be removed from the Cache only if they are not used within 10 minutes. insert ("data", "123", null, DateTime. maxValue, TimeSpan. fromMinutes (10); absolute policy, such as weather report, stores information for 60 minutes Cache. insert ("data", "123", null, DateTime. now. addMinutes (60), TimeSpan. zero); cache dependency. That is, the invalidation of a cache depends on another object. The object here can refer to another cache, or a file, or .... copy code class: CacheDependency namespace System. web. caching. cacheDependency depends on other cache projects System. web. caching. cacheDependency cacheDependency = new System. web. caching. cacheDependency (null, new string [] {"time"}); Cache. insert ("number", ++ num, cacheDependency); depends on the file or folder System. web. caching. cacheDependency cacheDependency = new System. web. caching. cacheDependency ("test. xml "); when test. system is automatically removed from the cache when the xml file is deleted or updated. web. caching. cacheDependency cacheDependency = new System. web. caching. cacheDependency (null, new string [] {"time"}); Cache. insert ("test", "123", cacheDependency); remove the project callback Cache. insert ("test", "123", null, DateTime. now. addSeconds (10), TimeSpan. zero, new CacheItemUpdateCallback (Test); private void Test (string key, CacheItemUpdateReason reason, out object expensiveObject, out CacheDependency dependency, out DateTime absoluteExpiration, out TimeSpan slidingExpiration ){}

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.