/// <summary> /// 判断CacheQueue中是否包含key键的Cache项 /// </summary> /// <param name="key">查询的cache项的键值</param> /// <returns>如果包含此键值,返回true,否则返回false</returns> /// <remarks> /// <code source="..\Framework\TestProjects\DeluxeWorks.Library.Test\Caching\CacheQueueTest.cs" region="AddRemoveClearTest" lang="cs" title="增加、移除、获取CacheItem项" /> /// </remarks> public bool ContainsKey(TKey key) { this.TotalCounters.HitRatioBaseCounter.Increment(); this.Counters.HitRatioBaseCounter.Increment(); this.rWLock.AcquireReaderLock(this.lockTimeout); try { bool result = ((InnerDictionary.ContainsKey(key) && ((CacheItem <TKey, TValue>)InnerDictionary[key]).Dependency == null) || (InnerDictionary.ContainsKey(key) && ((CacheItem <TKey, TValue>)InnerDictionary[key]).Dependency != null && !((CacheItem <TKey, TValue>)InnerDictionary[key]).Dependency.HasChanged)); if (result) { this.TotalCounters.HitsCounter.Increment(); this.TotalCounters.HitRatioCounter.Increment(); this.Counters.HitsCounter.Increment(); this.Counters.HitRatioCounter.Increment(); } else { this.TotalCounters.MissesCounter.Increment(); this.Counters.MissesCounter.Increment(); } return(result); } finally { this.rWLock.ReleaseReaderLock(); } }
/// <inheritdoc /> public bool ContainsKey(string key) { if (key == null) { throw new ArgumentNullException(nameof(key)); } if (InnerDictionary != null) { return(InnerDictionary.ContainsKey(key)); } else if (Properties != null) { for (var i = 0; i < Properties.Length; i++) { var property = Properties[i]; if (Comparer.Equals(property.Name, key)) { return(true); } } return(false); } else { return(false); } }
/// <summary> /// 判断CacheQueue中是否包含key键的Cache项 /// </summary> /// <param name="key">查询的cache项的键值</param> /// <returns>如果包含此键值,返回true,否则返回false</returns> /// <remarks> /// <code source="..\Framework\TestProjects\DeluxeWorks.Library.Test\Caching\CacheQueueTest.cs" region="AddRemoveClearTest" lang="cs" title="增加、移除、获取CacheItem项" /> /// </remarks> public bool ContainsKey(TKey key) { //this.TotalCounters.HitRatioBaseCounter.Increment(); //this.Counters.HitRatioBaseCounter.Increment(); return(this.DoReadFunc(() => { key = ConvertCacheKey(key); bool result = ((InnerDictionary.ContainsKey(key) && ((CacheItem <TKey, TValue>)InnerDictionary[key]).Dependency == null) || (InnerDictionary.ContainsKey(key) && ((CacheItem <TKey, TValue>)InnerDictionary[key]).Dependency != null && !((CacheItem <TKey, TValue>)InnerDictionary[key]).Dependency.HasChanged)); if (result) { //this.TotalCounters.HitsCounter.Increment(); //this.TotalCounters.HitRatioCounter.Increment(); //this.Counters.HitsCounter.Increment(); //this.Counters.HitRatioCounter.Increment(); } else { //this.TotalCounters.MissesCounter.Increment(); //this.Counters.MissesCounter.Increment(); } return result; })); }
public T3 Get(T1 key1, T2 key2) { if (InnerDictionary.ContainsKey(key1) && InnerDictionary[key1].ContainsKey(key2)) { return(InnerDictionary[key1][key2]); } return(default(T3)); }
public T3 Add(T1 value1, T2 value2, T3 value3) { if (!InnerDictionary.ContainsKey(value1)) { InnerDictionary.Add(value1, new Dictionary <T2, T3>()); } InnerDictionary[value1].Add(value2, value3); return(value3); }
public override LispExpression this[string key] { get { return(InnerDictionary.ContainsKey(key) ? InnerDictionary[key] : _parentContext[key]); } set { base[key] = value; } }
public bool Remove(string key) { if (InnerDictionary.ContainsKey(key)) { MethodParameterValue value = InnerDictionary[key]; if (value != null) { value.SetOwner(null); } } return(InnerDictionary.Remove(key)); }
private void LoadViewState(object savedState) { if (savedState != null) { Debug.Assert(savedState is Pair); Pair pair = (Pair)savedState; string[] names = (string[])pair.First; object[] states = (object[])pair.Second; for (int i = 0; i < names.Length; i++) { string key = names[i]; Debug.Assert(!InnerDictionary.ContainsKey(key), "The collection was not empty when loading the viewstate"); MethodParameterValue parameter = new MethodParameterValue(); Add(key, parameter); ((IStateManager)parameter).LoadViewState(states[i]); } } }
/// <summary> /// 向CacheQueue中增加一个有关联Dependency的Cache项,如果相应的key已经存在,则抛出异常 /// </summary> /// <param name="key">键</param> /// <param name="data">值</param> /// <param name="dependency">依赖:相对时间依赖、绝对时间依赖、文件依赖或混合依赖</param> /// <returns>值</returns> /// <remarks> /// <code source="..\Framework\TestProjects\DeluxeWorks.Library.Test\Caching\CacheQueueTest.cs" region="AddRemoveClearTest" lang="cs" title="增加、移除、获取CacheItem项" /> /// </remarks> public TValue Add(TKey key, TValue data, DependencyBase dependency) { this.rWLock.AcquireWriterLock(this.lockTimeout); try { InnerDictionary.MaxLength = this.MaxLength; //先删除已经存在而且过期的Cache项 if (InnerDictionary.ContainsKey(key) && ((CacheItem <TKey, TValue>)InnerDictionary[key]).Dependency != null && ((CacheItem <TKey, TValue>)InnerDictionary[key]).Dependency.HasChanged) { this.Remove(key); } CacheItem <TKey, TValue> item = new CacheItem <TKey, TValue>(key, data, dependency, this); if (dependency != null) { dependency.UtcLastModified = DateTime.UtcNow; dependency.UtcLastAccessTime = DateTime.UtcNow; } if (this.overrideExistsItem) { InnerDictionary[key] = item; } else { InnerDictionary.Add(key, item); } this.Counters.EntriesCounter.RawValue = InnerDictionary.Count; return(data); } finally { this.rWLock.ReleaseWriterLock(); } }
public bool ContainsKey(string key) { return(InnerDictionary.ContainsKey(key)); }
/// <summary> /// Checks if the collection contains a value /// </summary> /// <param name="value"></param> /// <returns></returns> public bool Contains(TValue value) { return(InnerDictionary.ContainsKey(KeySelector.Invoke(value))); }
/// <inheritdoc /> public bool ContainsKey(TKey key) { using (writeLock.LockRead()) return(InnerDictionary.ContainsKey(key)); }
bool IReadOnlyDictionary <TDestinationKey, TDestination> .ContainsKey(TDestinationKey key) => InnerDictionary.ContainsKey((TSourceKey)key);