本文整理汇总了C#中System.Runtime.Caching.CacheItem类的典型用法代码示例。如果您正苦于以下问题:C# CacheItem类的具体用法?C# CacheItem怎么用?C# CacheItem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CacheItem类属于System.Runtime.Caching命名空间,在下文中一共展示了CacheItem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetUserInfo
public LogonResultForm GetUserInfo(string userid)
{
var mapper = Common.GetMapperFromSession();
UserDao userdao = new UserDao(mapper);
var user = userdao.Query(new UserQueryForm { Name = userid }).FirstOrDefault();
if (user == null) throw new Exception("用户:" + userid + "在系统中不存在!");
if (user.Enabled == 0) throw new Exception("该用户已被禁用,请联系管理员!");
LogonResultForm result = new LogonResultForm();
UserInfoDao userInfoDao = new UserInfoDao(mapper);
RoleDao roleDao = new RoleDao(mapper);
LogonHistoryDao historyDao = new LogonHistoryDao(mapper);
string token = Guid.NewGuid().ToString().Replace("-", "");
var userinfo = userInfoDao.Query(new UserInfoQueryForm { ID = user.ID }).FirstOrDefault();
UserEntireInfo u = new UserEntireInfo { User = user };
if (userinfo != null) u.UserInfo = userinfo;
u.Role = roleDao.QueryRoleByUserID(u.User.ID);
CacheItem item = new CacheItem(token, u);
LogonHistory history = new LogonHistory
{
LogonTime = DateTime.Now,
Token = token,
UserID = user.ID,
ActiveTime = DateTime.Now,
};
historyDao.Add(history);
result.token = token;
result.UserInfo = userinfo;
cache.AddItem(item, 30 * 60);
MenuBLL menubll = new MenuBLL();
result.Menu = menubll.GetCurrentUserMenu(result.token);
return result;
}
示例2: CacheItem
void IDnsCache.Set(string key, byte[] bytes, int ttlSeconds)
{
CacheItem item = new CacheItem(key, bytes);
CacheItemPolicy policy = new CacheItemPolicy {AbsoluteExpiration = DateTimeOffset.Now + TimeSpan.FromSeconds(ttlSeconds)};
_cache.Add(item, policy);
}
示例3: Add
/// <summary>
/// 添加
/// </summary>
/// <param name="key"></param>
/// <param name="obj"></param>
public void Add(string key, object obj)
{
var cacheItem = new CacheItem(GeneralKey(key), obj);
var cacheItemPolicy = new CacheItemPolicy();
cache.Add(cacheItem, cacheItemPolicy);
}
示例4: AddItem
public void AddItem(CacheItem item, double span)
{
CacheItemPolicy cp = new CacheItemPolicy();
cp.SlidingExpiration.Add(TimeSpan.FromMinutes(span));
cache.Add(item, cp);
}
示例5: Add
public void Add(TenantInstance instance, Action<string, TenantInstance> removedCallback)
{
if (instance == null)
{
throw new ArgumentNullException("instance");
}
if (removedCallback == null)
{
removedCallback = delegate { };
}
// Add a cache entry for the instance id that will be used as a cache dependency
// for the running instances
var cacheDependencyPolicy = new CacheItemPolicy
{
// Make the "MaxAge" configurable - when the dependency is removed so are the instances
AbsoluteExpiration = DateTimeOffset.UtcNow.AddHours(12)
};
var cacheDependency = new CacheItem(instance.Id.ToString(), instance.Id);
// We need to add the dependency before we set up the instance change monitors,
// otherwise they'll be removed from the cache immediately!
cache.Set(instance.Id.ToString(), instance.Id, cacheDependencyPolicy);
// Now cache the running instance for each identifier
// The policies must be unique since the RemovedCallback can only be called once-per-policy
foreach (var id in instance.Tenant.RequestIdentifiers)
{
cache.Set(new CacheItem(id, instance), GetCacheItemPolicy(removedCallback, cacheDependency));
}
}
示例6: AddOrGetExisting
public override CacheItem AddOrGetExisting(CacheItem item, CacheItemPolicy policy)
{
if (item == null)
{
throw new ArgumentNullException("item");
}
return new CacheItem(item.Key, this.AddOrGetExistingInternal(item.Key, item.Value, policy));
}
示例7: AddPrincipalToCache
/// <summary>
/// Adds principal to cache
/// </summary>
/// <param name="principal">principal to add to cache</param>
public void AddPrincipalToCache(IJumbleblocksPrincipal principal)
{
if (principal != null)
{
var cacheItem = new CacheItem(principal.Identity.Name, principal);
Cache.Add(cacheItem, _defaultCachePolicy);
}
}
示例8: AddOrGetExisting
public override CacheItem AddOrGetExisting(CacheItem item, CacheItemPolicy policy)
{
var instance = GetCacheItem(item.Key);
if (instance != null)
return instance;
Set(item, policy);
return item;
}
示例9: Set
/// <summary>
/// 向缓存中设置缓存项
/// </summary>
/// <param name="key">该缓存项的唯一标识符。</param>
/// <param name="value">要插入的对象。</param>
/// <param name="minutesValue">分钟数,精确到最接近的毫秒。一个时段,必须在此时段内访问某个缓存项,否则将从内存中逐出该缓存项。</param>
/// <param name="removedCallback">在从缓存中移除某个缓存项后将调用该方法。</param>
public static void Set(string key, object value, double minutesValue, CacheEntryRemovedCallback RemovedCallback)
{
CacheItem item = new CacheItem(key, value);
CacheItemPolicy policy = new CacheItemPolicy();
policy.SlidingExpiration = TimeSpan.FromMinutes(minutesValue);
policy.RemovedCallback = RemovedCallback;
cache.Set(item, policy);
}
示例10: Login
public LoginResultForm Login(string username, string password)
{
LoginResultForm result = new LoginResultForm();
ISqlMapper mapper = MapperHelper.GetMapper();
UserDao userdao = new UserDao(mapper);
UserInfoDao userInfoDao = new UserInfoDao(mapper);
RoleDao roleDao = new RoleDao(mapper);
User_RoleDao urdao = new User_RoleDao(mapper);
LogonHistoryDao historyDao = new LogonHistoryDao(mapper);
MenuDao menudao = new MenuDao(mapper);
Menu_RoleDao mrdao = new Menu_RoleDao(mapper);
var user = userdao.Query(new UserQueryForm { Name = username, Password = password }).FirstOrDefault();
if (user != null)
{
if (user.Enabled == 0) throw new Exception("该用户已被禁用,请联系管理员!");
string token = Guid.NewGuid().ToString().Replace("-", "");
var userinfo = userInfoDao.Query(new UserInfoQueryForm { ID = user.ID }).FirstOrDefault();
var ur = urdao.Query(new User_RoleQueryForm { UserID = user.ID });
List<string> roleidlist = new List<string>();
ur.ForEach(t =>
{
roleidlist.Add(t.RoleID);
});
var roles = roleDao.Query(new RoleQueryForm { IDs = roleidlist });
var mrs = mrdao.Query(new Menu_RoleQueryForm { RoleIDs = roleidlist });
var menuids = (from mr in mrs select mr.MenuID).Distinct().ToList();
result.Menu = menudao.Query(new MenuQueryForm { IDs = menuids, Enabled = 1 });
UserEntireInfo u = new UserEntireInfo
{
User = user,
UserInfo = userinfo,
Role = roles,
};
CacheItem item = new CacheItem(token, u);
LogonHistory history = new LogonHistory
{
LogonTime = DateTime.Now,
Token = token,
UserID = user.ID,
ActiveTime = DateTime.Now,
};
historyDao.Add(history);
result.User = u;
result.token = token;
cache.AddItem(item, 1800);
//MonitorCache.GetInstance().PushMessage(new CacheMessage { Message = "login user:" + username + ",token:" + token }, SOAFramework.Library.CacheEnum.FormMonitor);
return result;
}
else
{
throw new Exception("用户名或者密码错误!请输入正确的用户名和密码!");
}
}
示例11: AddOrGetExisting
/// <summary>
/// return old entry if it is there.
/// </summary>
/// <param name="value"></param>
/// <param name="policy"></param>
/// <returns></returns>
public override CacheItem AddOrGetExisting(CacheItem value, CacheItemPolicy policy)
{
var old = Get(value.Key, value.RegionName);
Set(value, policy);
return old == null
? null
: new CacheItem(value.Key, old, value.RegionName);
}
示例12: Add
/// <summary>
/// Inserts a cache entry into the cache without overwriting any existing cache entry.
/// </summary>
/// <param name="cacheKey">A unique identifier for the cache entry.</param>
/// <param name="value">The object to insert.</param>
/// <param name="cachePolicy">An object that contains eviction details for the cache entry.</param>
/// <returns>
/// <c>true</c> if insertion succeeded, or <c>false</c> if there is an already an entry in the cache that has the same key as key.
/// </returns>
public bool Add(CacheKey cacheKey, object value, CachePolicy cachePolicy)
{
string key = GetKey(cacheKey);
var item = new CacheItem(key, value);
var policy = CreatePolicy(cacheKey, cachePolicy);
var existing = MemoryCache.Default.AddOrGetExisting(item, policy);
return existing.Value == null;
}
示例13: OnAddOrGetExisting
protected override object OnAddOrGetExisting(string prefixedKey, object value, DateTimeOffset absoluteExpiration)
{
var c = new CacheItem(prefixedKey, value);
var p = new CacheItemPolicy { AbsoluteExpiration = absoluteExpiration, Priority = System.Runtime.Caching.CacheItemPriority.Default };
var o = _core.AddOrGetExisting(c, p);
return o.Value;
}
示例14: _SetupMemoryCacheForTest
private static void _SetupMemoryCacheForTest()
{
var memoryCache = MemoryCache.Default;
var fileContents = File.ReadAllText(_contentFilePath);
var cacheItem = new CacheItem(_contentFilePath, fileContents);
var cacheItemPolicy = _GetCacheItemPolicy(_contentFilePath);
memoryCache.Set(cacheItem, cacheItemPolicy);
}
示例15: Set
public void Set(string key, object value, TimeSpan duration)
{
var item = new CacheItem(key, value);
var policy = new CacheItemPolicy()
{
AbsoluteExpiration = new DateTimeOffset(DateTime.Now.Add(duration))
};
_cache.Set(item, policy);
}