代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
CSharp
】
net 4.0 重写缓存类
作者:
Dezai.CN
/ 发布于
2011/3/15
/
815
<div> <pre class="code"><font face="微软雅黑"><font size="2"><span style="color: green">//.net 4.0 重写缓存类(拓展) </span><span style="color: blue">using </span>System.Web.Caching; <span style="color: blue">public class </span><span style="color: rgb(43,145,175)">InMemoryOutputCacheProvider </span>: </font></font><font face="微软雅黑"><font size="2"><span style="color: rgb(43,145,175)">OutputCacheProvider </span>{ <span style="color: blue">#region </span>Members <span style="color: blue">private </span><span style="color: rgb(43,145,175)">Dictionary</span><<span style="color: blue">string</span>, <span style="color: rgb(43,145,175)">InMemoryOutputCacheItem</span>> _cache = <span style="color: blue">new </span><span style="color: rgb(43,145,175)">Dictionary</span><<span style="color: blue">string</span>, <span style="color: rgb(43,145,175)">InMemoryOutputCacheItem</span>>(); <span style="color: blue">private readonly static object </span>_syncLock = <span style="color: blue">new object</span>(); </font></font><font face="微软雅黑"><font size="2"><span style="color: blue">#endregion #region </span>Methods <span style="color: blue">public override object </span>Add(<span style="color: blue">string </span>key, <span style="color: blue">object </span>entry, <span style="color: rgb(43,145,175)">DateTime </span>utcExpiry) { Set(key, entry, utcExpiry); <span style="color: blue">return </span>entry; } <span style="color: blue">public override object </span>Get(<span style="color: blue">string </span>key) { <span style="color: rgb(43,145,175)">InMemoryOutputCacheItem </span>item = <span style="color: blue">null</span>; <span style="color: blue">if </span>(_cache.TryGetValue(key, <span style="color: blue">out </span>item)) { <span style="color: blue">if </span>(item.UtcExpiry < <span style="color: rgb(43,145,175)">DateTime</span>.UtcNow) { Remove(key); <span style="color: blue">return null</span>; } <span style="color: blue">return </span>item.Value; } <span style="color: blue">return null</span>; } <span style="color: blue">public override void </span>Remove(<span style="color: blue">string </span>key) { <span style="color: rgb(43,145,175)">InMemoryOutputCacheItem </span>item = <span style="color: blue">null</span>; <span style="color: blue">if </span>(_cache.TryGetValue(key, <span style="color: blue">out </span>item)) { _cache.Remove(key); } } <span style="color: blue">public override void </span>Set(<span style="color: blue">string </span>key, <span style="color: blue">object </span>entry, <span style="color: rgb(43,145,175)">DateTime </span>utcExpiry) { <span style="color: blue">var </span>item = <span style="color: blue">new </span><span style="color: rgb(43,145,175)">InMemoryOutputCacheItem</span>(entry, utcExpiry); <span style="color: blue">lock </span>(_syncLock) { <span style="color: blue">if </span>(_cache.ContainsKey(key)) { _cache[key] = item; } </font></font><font face="微软雅黑"><font size="2"><span style="color: blue">else </span>{ _cache.Add(key, item); } } } </font></font><font face="微软雅黑"><font size="2"><span style="color: blue">#endregion </span>} <span style="color: blue">public class </span></font></font><font face="微软雅黑"><font size="2"><span style="color: rgb(43,145,175)">InMemoryOutputCacheItem </span>{ <span style="color: blue">#region </span>Members <span style="color: blue">public </span><span style="color: rgb(43,145,175)">DateTime </span>UtcExpiry { <span style="color: blue">get</span>; <span style="color: blue">set</span>; } <span style="color: blue">public object </span>Value { <span style="color: blue">get</span>; <span style="color: blue">set</span>; } </font></font><font face="微软雅黑"><font size="2"><span style="color: blue">#endregion #region </span>Ctor <span style="color: blue">public </span>InMemoryOutputCacheItem(<span style="color: blue">object </span>value, <span style="color: rgb(43,145,175)">DateTime </span>utcExpiry) { Value = value; UtcExpiry = utcExpiry; } </font></font><font face="微软雅黑"><font size="2"><span style="color: blue">#endregion </span>} </font></font></pre> <font size="2">//配置</font> <pre class="code"><font face="微软雅黑"><font size="2"> <span style="color: blue"><</span><span style="color: rgb(163,21,21)">caching</span></font></font><font face="微软雅黑"><font size="2"><span style="color: blue">> <</span><span style="color: rgb(163,21,21)">outputCache </span><span style="color: red">defaultProvider</span><span style="color: blue">=</span>"<span style="color: blue">InMemory</span>"</font></font><font face="微软雅黑"><font size="2"><span style="color: blue">> <</span><span style="color: rgb(163,21,21)">providers</span></font></font><font face="微软雅黑"><font size="2"><span style="color: blue">> <</span><span style="color: rgb(163,21,21)">add </span><span style="color: red">name</span><span style="color: blue">=</span>"<span style="color: blue">InMemory</span>" <span style="color: red">type</span><span style="color: blue">=</span>"<span style="color: blue">InMemoryOutputCacheProvider</span>"</font></font><font face="微软雅黑"><font size="2"><span style="color: blue">/> </</span><span style="color: rgb(163,21,21)">providers</span></font></font><font face="微软雅黑"><font size="2"><span style="color: blue">> </</span><span style="color: rgb(163,21,21)">outputCache</span></font></font><font face="微软雅黑"><font size="2"><span style="color: blue">> </</span><span style="color: rgb(163,21,21)">caching</span></font></font><span style="color: blue"><font size="2" face="微软雅黑">> </font></span></pre> <a href="http://11011.net/software/vspaste"></a> <font size="2">//页面</font> <pre class="code"><font face="微软雅黑"><font size="2"><span style="background: yellow"><%<span style="color: blue">@ </span><span style="color: maroon">OutputCache </span><span style="color: red">Duration</span><span style="color: blue">="15" </span><span style="color: red">VaryByParam</span><span style="color: blue">="*" </span></font></font><span style="background: yellow"><font size="2" face="微软雅黑">%> </font></span></pre> </div>
试试其它关键字
同语言下
.
文件IO 操作类库
.
Check图片类型[JPEG(.jpg 、.jpeg),TIF,GIF,BMP,PNG,P
.
机器名和IP取得(IPV4 IPV6)
.
Tiff转换Bitmap
.
linqHelper
.
MadieHelper.cs
.
RegHelper.cs
.
如果关闭一个窗体后激活另一个窗体的事件或方法
.
创建日志通用类
.
串口辅助开发类
可能有用的
.
文件IO 操作类库
.
Check图片类型[JPEG(.jpg 、.jpeg),TIF,GIF,BMP,PNG,P
.
机器名和IP取得(IPV4 IPV6)
.
Tiff转换Bitmap
.
linqHelper
.
MadieHelper.cs
.
RegHelper.cs
.
如果关闭一个窗体后激活另一个窗体的事件或方法
.
创建日志通用类
.
串口辅助开发类
Dezai.CN
贡献的其它代码
(
4037
)
.
多线程Socket服务器模块
.
生成随机密码
.
清除浮动样式
.
弹出窗口居中
.
抓取url的函数
.
使用base HTTP验证
.
div模拟iframe嵌入效果
.
通过header转向的方法
.
Session操作类
.
执行sqlite输入插入操作后获得自动编号的ID
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3