CacheHelper
public static ObjectCache Cache
{
get
{
return MemoryCache.Default;
}
}
public static bool TryGetCache<T>(string key, ref T value)
{
object v = null;
//Type t = typeof(T);
bool hit;
hit = TryGetCacheObject(key, ref v);
if (hit)
value = (T)v;
return hit;
}
public static bool TryGetCacheStruct<T>(string key, ref T value) where T : struct
{
object v = null;
bool hit = TryGetCacheObject(key, ref v);
if (hit)
value = (T)v;
return hit;
}
public static bool TryGetCacheObject(string key, ref object value)
{
object v = Cache.Get(key);
bool hit = false;
if (v == null)
hit = false;
else if (v == DBNull.Value)
{
hit = true;
value = null;
}
else
{
hit = true;
value = v;
}
TraceHelper.Trace("Cache", string.Format("TryGetCache({0}) = {1}", key, hit));
return hit;
}
public static bool ContainsCache(string key)
{
return Cache.Contains(key);
}
public static object GetCache(string key)
{
return Cache.Get(key);
}
public static void SetCache(string key, object value)
{
Cache.Set(key, value, CacheItemPolicy);
}
public static void SetCache(string key, object value, CacheItemPolicy cacheItemPolicy)
{
Cache.Set(key, value, cacheItemPolicy);
}
public static CacheItemPolicy CacheItemPolicy
{
get
{
CacheItemPolicy policy = new CacheItemPolicy();
policy.SlidingExpiration = , AppConfiguration.CacheSlidingExpirationInMins, );
return policy;
}
}
public static void ClearCacheByPrefix(string prefix)
{
List<string> keys = new List<string>();
foreach (var c in Cache)
{
if (c.Key.StartsWith(prefix))
{
keys.Add(c.Key);
}
}
foreach (var key in keys)
{
Cache.Remove(key);
}
}
Use:
string cachekey = string.Format("HasPermission_{0}_{1}", User.Id, functionName);
bool result = false;
if (!WebHelper.TryGetCache(cachekey, ref result))
{
result = roleBO.FunctionIsAllowForStaff(functionName, this.CurrentActualUser.Id);
WebHelper.SetCache(cachekey, result);
}
CacheHelper的更多相关文章
- 缓存工具类CacheHelper
代码: using System; using System.Collections.Generic; using System.Linq; using System.Text; using Syst ...
- MySqlHelper、CacheHelper
MySqlHelper代码: using System; using System.Collections; using System.Collections.Generic; using Syste ...
- [Cache] C#操作缓存--CacheHelper缓存帮助类 [复制链接]
using System;using System.Web;using System.Collections; namespace DotNet.Utilities{ public class Cac ...
- Asp.net Core CacheHelper 通用缓存帮助类
using System; using Microsoft.Extensions.Caching.Memory; using System.Runtime; namespace UFX.Tools { ...
- [Cache] C#操作缓存--CacheHelper缓存帮助类 (转载)
点击下载 CacheHelper.zip CacheHelper 缓存帮助类 C#怎么操作缓存 怎么设置和取缓存数据,都在这个类里面呢 下面看一下代码吧 /// <summary> /// ...
- CacheHelper工具类的使用
package com.bbcmart.util; import net.sf.ehcache.Cache; import net.sf.ehcache.CacheManager; import ne ...
- C#操作缓存--CacheHelper缓存帮助类
/// <summary>/// 类说明:Assistant/// 联系方式:361983679 /// 更新网站:<a href=\"http://www.cckan. ...
- C#缓存-依赖 CacheHelper
缓存依赖文件或文件夹 //创建缓存依赖项 CacheDependency dep = new CacheDependency(fileName);//Server.MapPath("&quo ...
- C# WebHelper-CookieHelper,CacheHelper,SessionHelper
常用web操作工具类,记录一下,本文记录的工具类,都要求引用 System.Web 1.CookieHelper /// <summary> /// Cookie工具类 /// </ ...
- WebHelper-SessionHelper、CookieHelper、CacheHelper、Tree
ylbtech-Unitity: cs-WebHelper-SessionHelper.CookieHelper.CacheHelper.Tree SessionHelper.cs CookieHel ...
随机推荐
- javascript:cors跨域postMessage、xhr2和xmldomain
一.h5 postMessage node http-server配置服务器 有关配置:请参考我的http://www.cnblogs.com/leee/p/5502727.html 我把文件夹a配置 ...
- NFA转DFA - json数字识别
json的主页上,提供了number类型的符号识别过程,如下: 图片引用:http://www.json.org/json-zh.html 实际上这张图片表示的是一个状态机,只是状态没有标出来.因为这 ...
- Xamarin.Android Binding
0.要绑定的jar库,需要保证编译jar使用的jdk版本,与绑定时xamarin使用的jdk版本一致. 查看编译jar的jdk版本的方法:jar解压后,a.看MANIFEST.MF b. javap ...
- 前端Javascript书籍分享
早前在公司曾做过一些关于前端的技术分享,而每每跟大家谈到深处时,大家会疑惑这些知识点从何而来. 我会经常在内部去推荐自己读过的好书,希望大家在技术层面上都能更上一个台阶. 今天写下这个帖子一方面是记录 ...
- Java基础语法
java基础学习总结——基础语法1 一.标识符
- URL转Drawable之 Android中获取网络图片的三种方法
转载自: http://doinone.iteye.com/blog/1074283 Android中获取网络图片是一件耗时的操作,如果直接获取有可能会出现应用程序无响应(ANR:Applicatio ...
- log4j使用快速入门【转】
1.引言 在应用程序中添加日志记录总的来说基于三个目的: .监视代码中变量的变化情况,周期性的记录到文件中供其他应用进行统计分析工作 .跟踪代码运行时轨迹,作为日后审计的依据 .担当集成开发环境中的调 ...
- python爬虫学习-爬取某个网站上的所有图片
最近简单地看了下python爬虫的视频.便自己尝试写了下爬虫操作,计划的是把某一个网站上的美女图全给爬下来,不过经过计算,查不多有好几百G的样子,还是算了.就首先下载一点点先看看. 本次爬虫使用的是p ...
- HBASE数据模型&扩展和负载均衡理论
示例数据模型 HBase中扩展和负载均衡的基本单元成为region,region本质上是以行健排序的连续存储区间.如果region太大,系统会把它们 自动拆分,相反的,就是把多个region合并,以减 ...
- http获取图片信息
一.安卓访问网络需要AndroidManifest.xml配置这样一个节点 <manifest> <uses-permission android:name="androi ...