Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx35 / System.ServiceModel.Web / System / ServiceModel / Dispatcher / NameValueCache.cs / 1305376 / NameValueCache.cs
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Linq;
using System.Text;
using System.Threading;
namespace System.ServiceModel.Dispatcher
{
class NameValueCache
{
// The NameValueCache implements a structure that uses a dictionary to map objects to
// indices of an array of cache entries. This allows us to store the cache entries in
// the order in which they were added to the cache, and yet still lookup any cache entry.
// The eviction policy of the cache is to evict the least-recently-added cache entry.
// Using a pointer to the next available cache entry in the array, we can always be sure
// that the given entry is the oldest entry.
Hashtable cache;
string[] currentKeys;
int nextAvailableCacheIndex;
object cachelock;
internal const int maxNumberofEntriesInCache = 16;
public NameValueCache()
: this(maxNumberofEntriesInCache)
{
}
public NameValueCache(int maxCacheEntries)
{
cache = new Hashtable();
currentKeys = new string[maxCacheEntries];
cachelock = new object();
}
public T Lookup(string key)
{
return (T)cache[key];
}
public void AddOrUpdate(string key, T value)
{
lock (cache)
{
if (!cache.ContainsKey(key))
{
if (!String.IsNullOrEmpty(currentKeys[nextAvailableCacheIndex]))
{
cache.Remove(currentKeys[nextAvailableCacheIndex]);
}
currentKeys[nextAvailableCacheIndex] = key;
nextAvailableCacheIndex = ++nextAvailableCacheIndex % currentKeys.Length;
}
cache[key] = value;
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- TypeSystem.cs
- SingleObjectCollection.cs
- PromptBuilder.cs
- TerminateDesigner.cs
- HtmlDocument.cs
- CheckableControlBaseAdapter.cs
- DataGridViewRowHeaderCell.cs
- TreeNodeStyle.cs
- TypeBuilder.cs
- ByteAnimationUsingKeyFrames.cs
- SchemaTableColumn.cs
- SelectionEditor.cs
- MarginsConverter.cs
- EncoderBestFitFallback.cs
- SqlUdtInfo.cs
- UnknownWrapper.cs
- XmlBinaryReader.cs
- PolicyException.cs
- CodeStatementCollection.cs
- _NtlmClient.cs
- BindingExpressionBase.cs
- WebScriptEnablingElement.cs
- WebServicesSection.cs
- Cursors.cs
- SecureStringHasher.cs
- SchemaSetCompiler.cs
- TypeConverterHelper.cs
- XmlFileEditor.cs
- StringFormat.cs
- TriggerBase.cs
- CompositeFontInfo.cs
- DataGridViewColumnStateChangedEventArgs.cs
- TextAdaptor.cs
- SetterBaseCollection.cs
- PartialCachingControl.cs
- EventData.cs
- BuildResultCache.cs
- ExpressionContext.cs
- MessageQueueConverter.cs
- CorrelationManager.cs
- MethodCallTranslator.cs
- XmlSchemaInfo.cs
- TimeSpanFormat.cs
- Encoding.cs
- FontStyleConverter.cs
- ToolStripItemClickedEventArgs.cs
- SqlDataSourceCommandEventArgs.cs
- XmlSchemaAny.cs
- ChildChangedEventArgs.cs
- LicFileLicenseProvider.cs
- WindowsSysHeader.cs
- InstanceNotFoundException.cs
- SqlTriggerAttribute.cs
- PromptEventArgs.cs
- AutomationProperty.cs
- ResourceIDHelper.cs
- DefaultEventAttribute.cs
- HTTPAPI_VERSION.cs
- HiddenFieldPageStatePersister.cs
- VerificationAttribute.cs
- ObjectToken.cs
- MessageEncoderFactory.cs
- XAMLParseException.cs
- InputMethodStateChangeEventArgs.cs
- KeyValueConfigurationCollection.cs
- RegisteredHiddenField.cs
- PairComparer.cs
- RecognizedAudio.cs
- CurrentTimeZone.cs
- BitmapEffectvisualstate.cs
- HandlerFactoryWrapper.cs
- OneOfScalarConst.cs
- FormattedTextSymbols.cs
- Barrier.cs
- WebPartCatalogAddVerb.cs
- GeneralTransformCollection.cs
- BigInt.cs
- PreviousTrackingServiceAttribute.cs
- HashMembershipCondition.cs
- DrawingGroup.cs
- LabelDesigner.cs
- ApplicationBuildProvider.cs
- documentsequencetextview.cs
- ContentHostHelper.cs
- ProtocolViolationException.cs
- ParallelEnumerableWrapper.cs
- DataSourceXmlSubItemAttribute.cs
- Renderer.cs
- OdbcCommand.cs
- Bidi.cs
- ObjectCache.cs
- _UriTypeConverter.cs
- LinkedResourceCollection.cs
- ComboBoxRenderer.cs
- CircleHotSpot.cs
- RectangleHotSpot.cs
- SymLanguageType.cs
- EntityDataSourceEntityTypeFilterItem.cs
- UIElement.cs
- LinqDataSourceValidationException.cs