C# System.Runtime.Caching使用
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();//取得或设定值,这个值会指定是否应该在指定期间过后清除
fileContents = //这里赋值;
oCache.Set("wechart_token", fileContents, policy);
}
return fileContents;
}
C# System.Runtime.Caching使用的更多相关文章
- HttpContext.Current.Cache和HttpRuntime.Cache的区别,以及System.Runtime.Caching
先看MSDN上的解释: HttpContext.Current.Cache:为当前 HTTP 请求获取Cache对象. HttpRuntime.Cache:获取当前应用程序的Cac ...
- System.Runtime.Caching中MemoryCache帮助类
值得参考的几个内存缓存帮助类: 参考资料: https://github.com/Hendy/memory-cache-helper https://gist.github.com/jdalley/0 ...
- VS2015 出现 .NETSystem.Runtime.Remoting.RemotingException: TCP 错误
错误内容: 界面显示内容为: .NET�������������System.Runtime.Remoting.RemotingException: TCP 淇¢亾鍗忚鍐茬獊: 搴斾负鎶ュご銆� 鍦 ...
- 找不到方法:“Boolean System.Runtime.Serialization.DataContractAttribute.get_IsReference()”的解决办法
找不到方法:“Boolean System.Runtime.Serialization.DataContractAttribute.get_IsReference()”.的解决办法站点发布后部署到了两 ...
- Could not load type 'System.Runtime.CompilerServices.ExtensionAttribute'
[TypeLoadException: Could not load type 'System.Runtime.CompilerServices.ExtensionAttribute' from as ...
- 重写成员“log4net.Util.ReadOnlyPropertiesDictionary.GetObjectData(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)”时违反了继承安全性规则
在.NET 4.0下使用最新版本的log4Net 1.2.10,会遇到下面这样的错误: 重写成员“log4net.Util.ReadOnlyPropertiesDictionary.GetObject ...
- IIS提示“异常详细信息: System.Runtime.InteropServices.ExternalException: 无法执行程序”
先来看错误提示: 无法执行程序.所执行的命令为 "C:/Windows/Microsoft.NET/Framework/v3.5/csc.exe" /noconfig /fullp ...
- System.Web.Caching.Cache类 缓存
1.文件缓存依赖 public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender ...
- System.Runtime.InteropServices.COMException: Exception from HRESULT: 0x800AC472
更新至服务器后运行出错: System.Runtime.InteropServices.COMException: Exception from HRESULT: 0x800AC472 解决方法 注册 ...
随机推荐
- 2003server r2 + sql 2000 sp4 环境配置
由于工作需求需要配置一个windows 2003 server r2 + sql 2000 sp4的环境: 一.2003server准备系统: msdn 下载 分清x86还是x64 一共有两个cd准备 ...
- oracle登录管理员创建数据库和表空间
登录管理员最高权限账号 cmd输入sqlplus 回车,或者直接打开sqlplus 用户名:sys 密码:sys as sysdba 1.首先,创建(新)用户: create user usernam ...
- Lesson 28 No parking
Text Jasper White is one of those rare people who believes in ancient myths. He has just bought a ne ...
- 算法与数据结构(十) 二叉排序树的查找、插入与删除(Swift版)
在上一篇博客中,我们主要介绍了四种查找的方法,包括顺序查找.折半查找.插入查找以及Fibonacci查找.上面这几种查找方式都是基于线性表的查找方式,今天博客中我们来介绍一下基于二叉树结构的查找,也就 ...
- 值得收藏!!javascript数组中多条对象去重方式,很实用!!!
在数组中都是数字的时候很好去重,例如:var arr=[1,2,2,2,3,4,5,4,5,3,6]:可以用两层for循环或者其他方式进行去重 我在这里也给出一个方法吧: Array.prototy ...
- [Swift]LeetCode951. 翻转等价二叉树 | Flip Equivalent Binary Trees
For a binary tree T, we can define a flip operation as follows: choose any node, and swap the left a ...
- Vmware安装Ubuntu ==> 连网成功
由于工作需要,得把NS3安装到内网服务器中,大家知道这个是不能连接外网的,学校又没有Ubuntu高校源.NS3要先安装一大堆的依赖,让人头痛的是在内网里有没发以终端指令形式安装,针对这种麻烦,找到两个 ...
- IO复用(较详细)
进程与线程的描述 一个进程至少会创建一个线程,多个线程共享一个程序进程的内存.程序的运行最终是靠线程来完成操作的.线程的数量跟CPU核数有关,一个核最多能发出两个线程.线程的操作主要分为:一:给CPU ...
- 了解 HTTPS,读这篇文章就够了
今天接到个活儿,让我科普 HTTPS .讲 HTTP 我都“方”,想要通俗易懂的说完 HTTPS, 我有点“圆”.在讲什么是 HTTPS 之前,我们先来看个漫画. △ 图片来源于阮一峰的网络日志 ...
- 虎牙数万主播同时在线直播的秘密,CDN推流日志上行实时监控
6 月 10 日,又拍云 Open Talk | 2018 音视频技术沙龙·深圳站 顺利落幕,来自虎牙的直播运维研发架构师张波在沙龙上做了<基于CDN推流日志的主播上行实时监控及其自动化解密&g ...