/// <summary>
        /// 在Cache中读取Cache项,如果不存在,则调用action
        /// </summary>
        /// <param name="key">键值</param>
        /// <param name="action">不存在时的回调</param>
        /// <returns>Cache项的值</returns>
        public TValue GetOrAddNewValue(TKey key, PortableCacheItemNotExistsAction action)
        {
            TValue result = default(TValue);

            if (TryGetValue(key, out result) == false)
            {
                lock (this.syncRoot)
                {
                    if (TryGetValue(key, out result) == false)
                    {
                        result = action(this, key);
                    }
                }
            }

            return(result);
        }
Пример #2
0
        /// <summary>
        /// 在Cache中读取Cache项,如果不存在,则调用action
        /// </summary>
        /// <param name="key">键值</param>
        /// <param name="action">不存在时的回调</param>
        /// <returns>Cache项的值</returns>
        public TValue GetOrAddNewValue(TKey key, PortableCacheItemNotExistsAction action)
        {
            key = ConvertCacheKey(key);

            TValue result;

            if (this.InnerTryGetValue(key, out result) == false)
            {
                lock (this.syncRoot)
                {
                    if (this.InnerTryGetValue(key, out result) == false)
                    {
                        result = action(this, key);
                    }
                }
            }

            return(result);
        }
Пример #3
0
        public Delegate GetOrAddNewValue(FieldInfo fieldInfo, Type valueType, PortableCacheItemNotExistsAction action)
        {
            FieldMethodDelegateCacheKey key = new FieldMethodDelegateCacheKey(fieldInfo, valueType);

            return(GetOrAddNewValue(key, action));
        }
        public Delegate GetOrAddNewValue(PropertyInfo propertyInfo, Type valueType, PortableCacheItemNotExistsAction action)
        {
            PropertyMethodDelegateCacheKey key = new PropertyMethodDelegateCacheKey(propertyInfo, valueType);

            return(GetOrAddNewValue(key, action));
        }