日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > C# >内容正文

C#

C#缓存absoluteExpiration、slidingExpiration两个参数的疑惑

發布時間:2025/3/15 C# 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 C#缓存absoluteExpiration、slidingExpiration两个参数的疑惑 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

看了很多資料終于搞明白cache中absoluteExpiration,slidingExpiration這兩個參數的含義。

absoluteExpiration:用于設置絕對過期時間,它表示只要時間一到就過期,所以類型為System.DateTime,當給這個參數設置了一個時間時,slidingExpiration參數的值就只能為Cache.NoSlidingExpiration,否則出錯;

slidingExpiration:用于設置可調過期時間,它表示當離最后訪問超過某個時間段后就過期,所以類型為System.TimeSpan,當給這個參數設置了一個時間段時,absoluteExpiration的值就只能為Cache.NoAbsoluteExpiration,否則出錯;

???? 兩個使用實例

Cache.Add("name", content, null, System.Web.Caching.Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(10), System.Web.Caching.CacheItemPriority.Normal, null);

Cache.Add("name", content, null, DateTime.Now.AddMinutes(10), System.Web.Caching.Cache.NoSlidingExpiration, CacheItemPriority.Normal, null);

?

?

? //
??????? // 摘要:
??????? //???? Inserts an object into the System.Web.Caching.Cache object together with dependencies,
??????? //???? expiration policies, and a delegate that you can use to notify the application
??????? //???? before the item is removed from the cache.
??????? //
??????? // 參數:
??????? //?? key:
??????? //???? The cache key that is used to reference the object.
??????? //
??????? //?? value:
??????? //???? The object to insert into the cache.
??????? //
??????? //?? dependencies:
??????? //???? The file or cache key dependencies for the item. When any dependency changes,
??????? //???? the object becomes invalid and is removed from the cache. If there are no dependencies,
??????? //???? this parameter contains null.
??????? //
??????? //?? absoluteExpiration:
??????? //???? The time at which the inserted object expires and is removed from the cache.
??????? //???? To avoid possible issues with local time such as changes from standard time to
??????? //???? daylight saving time, use System.DateTime.UtcNow instead of System.DateTime.Now
??????? //???? for this parameter value. If you are using absolute expiration, the slidingExpiration
??????? //???? parameter must be set to System.Web.Caching.Cache.NoSlidingExpiration.
??????? //
??????? //?? slidingExpiration:
??????? //???? The interval between the time that the cached object was last accessed and the
??????? //???? time at which that object expires. If this value is the equivalent of 20 minutes,
??????? //???? the object will expire and be removed from the cache 20 minutes after it was
??????? //???? last accessed. If you are using sliding expiration, the absoluteExpiration parameter
??????? //???? must be set to System.Web.Caching.Cache.NoAbsoluteExpiration.
??????? //
??????? //?? onUpdateCallback:
??????? //???? A delegate that will be called before the object is removed from the cache. You
??????? //???? can use this to update the cached item and ensure that it is not removed from
??????? //???? the cache.
??????? //
??????? // 異常:
??????? //?? T:System.ArgumentNullException:
??????? //???? The key, value, or onUpdateCallback parameter is null.
??????? //
??????? //?? T:System.ArgumentOutOfRangeException:
??????? //???? You set the slidingExpiration parameter to less than TimeSpan.Zero or the equivalent
??????? //???? of more than one year.
??????? //
??????? //?? T:System.ArgumentException:
??????? //???? The absoluteExpiration and slidingExpiration parameters are both set for the
??????? //???? item you are trying to add to the Cache.-or-The dependencies parameter is null,
??????? //???? and the absoluteExpiration parameter is set to System.Web.Caching.Cache.NoAbsoluteExpiration,
??????? //???? and the slidingExpiration parameter is set to System.Web.Caching.Cache.NoSlidingExpiration.
??????? public void Insert(string key, object value, CacheDependency dependencies, DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemUpdateCallback onUpdateCallback);

轉載于:https://www.cnblogs.com/maijin/p/7049355.html

總結

以上是生活随笔為你收集整理的C#缓存absoluteExpiration、slidingExpiration两个参数的疑惑的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。