示例#1
0
            /// <summary>
            ///     Gets the user account cache entry.
            /// </summary>
            /// <param name="username">The username.</param>
            /// <returns></returns>
            private UserAccountCacheEntry GetUserAccountCacheEntry(string username)
            {
                UserAccountCacheEntry entry;

                lock ( _innerLockObject )
                {
                    if (PasswordPolicyId == 0)
                    {
                        // Cache the password policy instance id
                        PasswordPolicyId = Entity.GetId("core:passwordPolicyInstance");
                    }

                    if (!InnerCache.TryGetValue(username, out entry))
                    {
                        // We don't have a cache entry for this user name.
                        // Get the user account by user name and add it to the cache
                        UserAccount userAccountByName = Entity.GetByField <UserAccount>(username, true, new EntityRef("core", "name")).FirstOrDefault( );

                        if (userAccountByName == null)
                        {
                            return(null);
                        }

                        entry = AddAccount(userAccountByName);
                    }
                }

                return(entry);
            }
示例#2
0
        /// <summary>
        /// Gets or sets the <see cref="System.Object" /> with the specified key.
        /// </summary>
        /// <value>
        /// The <see cref="System.Object" />.
        /// </value>
        /// <param name="key">The key.</param>
        /// <returns>
        /// The cached value if found; null otherwise.
        /// </returns>
        public TValue this[TKey key]
        {
            get
            {
                bool   result;
                TValue value;

                result = InnerCache.TryGetValue(key, out value);

                if (result)
                {
                    Interlocked.Increment(ref _hits);
                }
                else
                {
                    Interlocked.Increment(ref _misses);
                }

                MetricReporter.NotifyHitsAndMissesChange(Name);

                return(value);
            }
            set
            {
                Add(key, value);
            }
        }
示例#3
0
        protected async Task InvalidateAsync(string partitionKey)
        {
            await Task.Run(() =>
            {
                if (InnerCache.TryGetValue(partitionKey, out HashSet <string> index))
                {
                    Parallel.ForEach(index, InnerCache.Remove);

                    InnerCache.Remove(partitionKey);
                }
            });
        }
示例#4
0
        /// <summary>
        ///     Attempts to retrieve the value with the specified key.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="value">The value.</param>
        /// <returns>
        ///     <c>true</c> if the cache contains the specified key; otherwise, <c>false</c>.
        /// </returns>
        public bool TryGetValue(TKey key, out TValue value)
        {
            RedisValue redisValue = RedisValue.Null;

            bool result = false;

            if (!RedisCacheMemoryStoreSuppressionContext.IsSet(CacheName))
            {
                result = _memoryStore.TryGetString(GetRedisKey(key), out redisValue);
            }

            if (!result && InnerCache != null)
            {
                return(InnerCache.TryGetValue(key, out value));
            }

            value = GetValue(redisValue);
            return(result);
        }
示例#5
0
        /// <summary>
        /// Attempts to retrieve the value with the specified key.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="value">The value.</param>
        /// <returns>
        /// <c>true</c> if the cache contains the specified key; otherwise, <c>false</c>.
        /// </returns>
        public bool TryGetValue(TKey key, out TValue value)
        {
            bool result;

            result = InnerCache.TryGetValue(key, out value);

            if (result)
            {
                Interlocked.Increment(ref _hits);
            }
            else
            {
                Interlocked.Increment(ref _misses);
            }

            MetricReporter.NotifyHitsAndMissesChange(Name);

            return(result);
        }
示例#6
0
 /// <summary>
 ///     Attempts to retrieve the value with the specified key.
 /// </summary>
 /// <param name="key">The key.</param>
 /// <param name="value">The value.</param>
 /// <returns>
 ///     <c>true</c> if the cache contains the specified key; otherwise, <c>false</c>.
 /// </returns>
 public bool TryGetValue(TKey key, out TValue value)
 {
     return(InnerCache.TryGetValue(key, out value));
 }