欢迎来到天天文库
浏览记录
ID:49658411
大小:63.07 KB
页数:12页
时间:2020-03-03
《Net通用基础框架(Net Common Infrastructure)-缓存.docx》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、缓存可以提高网站性能,减轻数据库压力。网站中常用的缓存分为业务数据缓存和页面文件缓存两类,其中业务数据缓存常用AspnetCache,Memcached等,而页面文件缓存常用Squid和Nginx,今天介绍的内容是业务数据缓存。·Common.Cache类图·缓存接口ICache:使用Add方法时,如果key存在,则返回false。使用Set方法时,key不存在则添加,否则更新。usingSystem;usingSystem.Collections.Generic;namespaceCommon.Cache{
2、//////缓存///publicinterfaceICache{//////增加//////类型///键///值///结果boolAdd(stringkey,Tvalue);//////增加///3、ary>///类型///键///值///持续时间///结果boolAdd(stringkey,Tvalue,TimeSpanduration);//////清除///voidClear();///4、ary>///获取//////类型///键///值TGet(stringkey);//////多线程获取//////键集合///值集合IDictionaryMultiGet(ILi
3、ary>///类型///键///值///持续时间///结果boolAdd(stringkey,Tvalue,TimeSpanduration);//////清除///voidClear();///4、ary>///获取///
4、ary>///获取///
5、stkeys);//////移除//////键voidRemove(stringkey);//////设置//////类型///键///值///结果boolSet
6、(stringkey,Tvalue);//////设置//////类型///键///值///持续时间///结果boolSet(stringkey,Tvalue,TimeSpanduration);}}·缓存
7、基类usingSystem;usingSystem.Collections.Generic;namespaceCommon.Cache{//////缓存基类///publicabstractclassCacheBase:ICache{privateTimeSpanmaxDuration=TimeSpan.FromDays(15);//////最长持续时间///publicTimeSpanMaxDuration{get{returnth
8、is.maxDuration;}set{this.maxDuration=value;}}//////前缀///publicstringPrefix{get;set;}publicboolAdd(stringkey,Tvalue){returnthis.Add(key,value,this.MaxDuration);}publicabstractbo
此文档下载收益归作者所有