背景:

  公司的老框架里的登录信息用的MemoryCache保存的,为了实现单用户登录(即一个账号不能同事登录),需要在登录前对已经登录的信息做遍历。

大致思路如下:

本方法可用于清除所有的缓存。

1、HttpRuntime.Cache

   System.Collections.IDictionaryEnumerator cacheEnum = HttpRuntime.Cache.GetEnumerator();
   while(cacheEnum.MoveNext()) { //cacheEnum.Key.ToString()为缓存名称,cacheEnum.Value为缓存值 }

2、System.Runtime.Caching.ObjectCache
   ObjectCache cache = MemoryCache.Default
   IEnumerable<KeyValuePair<string, object>> items = cache.AsEnumerable();
   foreach (KeyValuePair<string, object> item in items) { //item.Key为缓存名称, item.Value为缓存值 }

这个缓存是.NET4.0新增的。

班门弄斧的补充说明单用户登录实现原理:

单用户登录时,对已经登录用户信息做遍历,发现同一个登录账号,就将其从缓存里移除,再做登录即可

(分布式缓存的后续再补充吧!)

2015-02-05

wujf

有追求,才有动力!

相关文章:

  • 2021-06-17
  • 2022-12-23
  • 2021-06-06
  • 2021-12-27
  • 2022-12-23
  • 2022-01-13
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-05-15
  • 2022-12-23
  • 2022-12-23
  • 2022-02-09
相关资源
相似解决方案