private static int GetCountImmediate(IConfigurationSession session, OrganizationId orgId, string systemAddressListName)
        {
            AddressBookBase systemAddressList = SystemAddressListMemberCount.ReadSystemAddressListFromAD(session, orgId, systemAddressListName);
            SystemAddressListMemberCountCacheValue systemAddressListMemberCountCacheValue = new SystemAddressListMemberCountCacheValue(systemAddressList);

            return(systemAddressListMemberCountCacheValue.GetMemberCountImmediate(session));
        }
        private static int GetCountFromCache(IConfigurationSession session, OrganizationId orgId, string systemAddressListName, int quota)
        {
            int?num = null;
            SystemAddressListMemberCountCacheKey   key = new SystemAddressListMemberCountCacheKey(orgId, systemAddressListName);
            SystemAddressListMemberCountCacheValue systemAddressListMemberCountCacheValue = null;

            try
            {
                if (!SystemAddressListMemberCount.cachedAddressListLock.TryEnterReadLock(SystemAddressListMemberCount.readerLockTimeout))
                {
                    throw new TransientException(DirectoryStrings.ErrorTimeoutReadingSystemAddressListCache);
                }
                SystemAddressListMemberCount.memberCountCache.TryGetValue(key, out systemAddressListMemberCountCacheValue);
            }
            finally
            {
                try
                {
                    SystemAddressListMemberCount.cachedAddressListLock.ExitReadLock();
                }
                catch (SynchronizationLockException)
                {
                }
            }
            if (systemAddressListMemberCountCacheValue == null)
            {
                try
                {
                    if (!SystemAddressListMemberCount.cachedAddressListLock.TryEnterUpgradeableReadLock(SystemAddressListMemberCount.readerLockTimeout))
                    {
                        throw new TransientException(DirectoryStrings.ErrorTimeoutReadingSystemAddressListCache);
                    }
                    if (!SystemAddressListMemberCount.memberCountCache.TryGetValue(key, out systemAddressListMemberCountCacheValue))
                    {
                        AddressBookBase systemAddressList = SystemAddressListMemberCount.ReadSystemAddressListFromAD(session, orgId, systemAddressListName);
                        systemAddressListMemberCountCacheValue = new SystemAddressListMemberCountCacheValue(systemAddressList);
                        num = new int?(systemAddressListMemberCountCacheValue.InitializeMemberCount(session, ExDateTime.UtcNow, quota));
                        if (!SystemAddressListMemberCount.cachedAddressListLock.TryEnterWriteLock(SystemAddressListMemberCount.writerLockTimeout))
                        {
                            throw new TransientException(DirectoryStrings.ErrorTimeoutWritingSystemAddressListCache);
                        }
                        try
                        {
                            SystemAddressListMemberCount.memberCountCache.Add(key, systemAddressListMemberCountCacheValue);
                        }
                        finally
                        {
                            SystemAddressListMemberCount.cachedAddressListLock.ExitWriteLock();
                        }
                    }
                }
                finally
                {
                    try
                    {
                        SystemAddressListMemberCount.cachedAddressListLock.ExitUpgradeableReadLock();
                    }
                    catch (SynchronizationLockException)
                    {
                    }
                }
            }
            if (num == null)
            {
                num = new int?(systemAddressListMemberCountCacheValue.GetMemberCount(session, ExDateTime.UtcNow, quota));
            }
            return(num.Value);
        }