码迷,mamicode.com
首页 > Windows程序 > 详细

C# System.Runtime.Caching使用

时间:2017-03-23 19:10:14      阅读:365      评论:0      收藏:0      [点我收藏+]

标签:get   static   char   标记   重写   使用   net   art   system   

System.Runtime.Caching命名空间是.NET 4.0新增的,目的是将以前的.NET 版本中的System.Web.Caching单独提取出来,独立使用,这样web和其他.NET程序如WPF都可以使用。

System.Runtime.Caching包含缓存类和监视类,包括文件、数据库、缓存等的监视,与以前在System.Web.Caching中的一样,但重新包装。

可以预见在以后的版本中,System.Web.Caching命名空间会被标记为Obsolete(过时),或者重写为包装System.Runtime.Caching中的方法。

 

using System.Runtime.Caching;
public static string GetToken()
        {
            ObjectCache oCache = MemoryCache.Default;
            string fileContents = oCache["wechart_token"] as string;
            if (fileContents == null)
            {
                CacheItemPolicy policy = new CacheItemPolicy();
                policy.AbsoluteExpiration = DateTime.Now.AddMinutes(120);//取得或设定值,这个值会指定是否应该在指定期间过后清除
                fileContents = //这里赋值;
                oCache.Set("wechart_token", fileContents, policy);
            }
            return fileContents;
        }

 

C# System.Runtime.Caching使用

标签:get   static   char   标记   重写   使用   net   art   system   

原文地址:http://www.cnblogs.com/xuwendong/p/6606456.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!