zoukankan      html  css  js  c++  java
  • .net framework缓存遍历

    背景:

      公司的老框架里的登录信息用的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

    有追求,才有动力!

    后台兼职接单中,联系我微信:wjf88520

    by wujf

    mail:921252375@qq.com

  • 相关阅读:
    windows cmd 编码
    ARM伪指令
    System.load 和 System.loadLibrary
    用GDB调试程序
    ARM指令集
    ARM寻址方式
    abortion
    Oxford City Jealous Lover
    everyday words
    【转】高效率的C++函数返回值
  • 原文地址:https://www.cnblogs.com/wujf/p/4275387.html
Copyright © 2011-2022 走看看