示例#1
0
        internal static DelegatedPrincipalCacheData GetEntry(string targetOrgId, string userId, string securityToken)
        {
            DelegatedPrincipalCache.CacheKey key = new DelegatedPrincipalCache.CacheKey(targetOrgId, userId, securityToken);
            DelegatedPrincipalCacheData      delegatedPrincipalCacheData = null;

            if (DelegatedPrincipalCache.delegatedCache.ContainsKey(key))
            {
                lock (DelegatedPrincipalCache.syncObj)
                {
                    if (DelegatedPrincipalCache.delegatedCache.TryGetValue(key, out delegatedPrincipalCacheData))
                    {
                        if (delegatedPrincipalCacheData != null && DelegatedPrincipalCache.IsCacheBucketExpired(delegatedPrincipalCacheData))
                        {
                            DelegatedPrincipalCache.delegatedCache.Remove(key);
                            delegatedPrincipalCacheData = null;
                        }
                        else
                        {
                            delegatedPrincipalCacheData.LastReadTime = DateTime.UtcNow;
                        }
                    }
                }
            }
            return(delegatedPrincipalCacheData);
        }
示例#2
0
 internal static void Cleanup()
 {
     if (DelegatedPrincipalCache.cleanupTime > DateTime.UtcNow)
     {
         return;
     }
     lock (DelegatedPrincipalCache.syncObj)
     {
         if (!(DelegatedPrincipalCache.cleanupTime > DateTime.UtcNow))
         {
             List <DelegatedPrincipalCache.CacheKey> list = new List <DelegatedPrincipalCache.CacheKey>();
             foreach (DelegatedPrincipalCache.CacheKey cacheKey in DelegatedPrincipalCache.delegatedCache.Keys)
             {
                 DelegatedPrincipalCacheData data = DelegatedPrincipalCache.delegatedCache[cacheKey];
                 if (DelegatedPrincipalCache.IsCacheBucketExpired(data))
                 {
                     list.Add(cacheKey);
                 }
             }
             foreach (DelegatedPrincipalCache.CacheKey key in list)
             {
                 DelegatedPrincipalCache.delegatedCache.Remove(key);
             }
             DelegatedPrincipalCache.cleanupTime = DateTime.UtcNow.AddHours(6.0);
         }
     }
 }
示例#3
0
 private static bool IsCacheBucketExpired(DelegatedPrincipalCacheData data)
 {
     if (data == null)
     {
         throw new ArgumentNullException("data");
     }
     return(data.IsExpired() && data.LastReadTime.AddMinutes(6.0) < DateTime.UtcNow);
 }
示例#4
0
        internal static bool TrySetEntry(string targetOrgId, string userId, string securityToken, DelegatedPrincipalCacheData data)
        {
            DelegatedPrincipalCache.CacheKey key = new DelegatedPrincipalCache.CacheKey(targetOrgId, userId, securityToken);
            bool result = false;

            lock (DelegatedPrincipalCache.syncObj)
            {
                if (DelegatedPrincipalCache.delegatedCache.Count < 5000)
                {
                    DelegatedPrincipalCache.delegatedCache[key] = data;
                    result = true;
                }
            }
            return(result);
        }