Caching: Local cache and distributed cache and cache expiration time settings

Source: Internet
Author: User

1, first for the local memory cache, is to cache the data in the native memory, as shown in 1:

2, distributed cache mechanism: There may be cross-process, access to cache data across domains

For distributed caches, because the cached data is placed in the cache server, or, at this point, the application needs to go across the process to access the distributed cache server, 2:

When we use cross-process caching mechanisms in our applications, such as distributed cache memcached or Microsoft AppFabric, data is cached in processes outside the application. Each time, when we want to cache some data, the cached API will first serialize the data into bytes, and then send these bytes to the cache server to save. Similarly, when we want to use cached data again in our application, the cache server sends the cached bytes to the application, and the cached client class library takes the bytes and then deserializes it into the data object we need.

It is also important to note that:

This mechanism of serialization and deserialization occurs on the application server, and the cache server is only responsible for saving it.

. The default serialization mechanism used in net is not optimal because it uses the reflection mechanism, and the reflection mechanism is CPU-intensive, especially when we cache more complex data objects.

In general, the caching mechanism will set the absolute expiration and relative expiration times

3. Time setting

3.1. Set the absolute expiration time

<summary>//        set an absolute expiry time///</summary>//        <param name= "CacheKey" ></param> //        <param name= "Objobject" ></param>///        <param name= "seconds" > expired after how many seconds </param> Public        static void Setcachedatetime (String CacheKey, Object Objobject, long Seconds)         {            System.Web.Caching.Cache objcache = Httpruntime.cache;            Objcache.insert (CacheKey, objobject, NULL, System.DateTime.Now.AddSeconds (Seconds), TimeSpan.Zero);        }

3.2. Set the relative expiration time

<summary>///        Set current application specifies cache value with relative expiration time///</summary>//        <param name= "CacheKey" > </param>//        <param name= "Objobject" ></param>//        <param name= "TimeSpan" > The amount of time that is not called is invalidated, in seconds </param> public        static void Setcachetimespan (String CacheKey, Object Objobject,long TimeSpan)         {            System.Web.Caching.Cache objcache = Httpruntime.cache;            Objcache.insert (CacheKey, objobject, NULL, DateTime.MaxValue, Timespan.fromseconds (TimeSpan));        }

Links: http://www.infoq.com/cn/articles/misunderstanding-using-cache/

Http://www.cnblogs.com/wuyifu/p/3956476.html

Caching: Local cache and distributed cache and cache expiration time settings

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.