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
- ApplicationSettingsBase.cs
- MbpInfo.cs
- EdmItemCollection.cs
- CombinedGeometry.cs
- HttpHandlerActionCollection.cs
- SendingRequestEventArgs.cs
- SqlDataSourceView.cs
- SiblingIterators.cs
- coordinator.cs
- InputBuffer.cs
- ILGen.cs
- TimeSpanSecondsConverter.cs
- DataServiceQueryContinuation.cs
- DialogWindow.cs
- ProgramNode.cs
- ControlType.cs
- VirtualDirectoryMapping.cs
- XmlFileEditor.cs
- ValidationSummary.cs
- XsdBuilder.cs
- SessionSwitchEventArgs.cs
- BitmapEffectInputData.cs
- SmiConnection.cs
- TextTreeText.cs
- XmlReaderSettings.cs
- GroupDescription.cs
- EventManager.cs
- Attributes.cs
- ObjectDataSourceDisposingEventArgs.cs
- XmlSchemaElement.cs
- GroupStyle.cs
- NotFiniteNumberException.cs
- ProcessModule.cs
- DateTimeUtil.cs
- GeometryGroup.cs
- SudsCommon.cs
- XmlIlVisitor.cs
- PointHitTestParameters.cs
- DoubleKeyFrameCollection.cs
- Decoder.cs
- XmlAnyElementAttribute.cs
- UInt64.cs
- SqlCommand.cs
- ManualResetEvent.cs
- ChangeDirector.cs
- AnimationException.cs
- ListViewItemCollectionEditor.cs
- ExpressionPrefixAttribute.cs
- TextProviderWrapper.cs
- X509ClientCertificateCredentialsElement.cs
- Exceptions.cs
- ParserStack.cs
- StringFreezingAttribute.cs
- UnmanagedMemoryStream.cs
- CheckBoxRenderer.cs
- ObjectDataSourceStatusEventArgs.cs
- PropertyAccessVisitor.cs
- OleDbMetaDataFactory.cs
- XpsSerializerWriter.cs
- PageParser.cs
- DBDataPermissionAttribute.cs
- MobilePage.cs
- HttpHandlerActionCollection.cs
- DataObjectPastingEventArgs.cs
- WorkflowMarkupSerializationException.cs
- MenuItemStyleCollection.cs
- ConstraintManager.cs
- ColumnClickEvent.cs
- FusionWrap.cs
- OpenTypeCommon.cs
- SecurityException.cs
- BuildProviderAppliesToAttribute.cs
- WinFormsSecurity.cs
- TargetInvocationException.cs
- ExceptionUtil.cs
- WebPartConnectionsDisconnectVerb.cs
- TypeCollectionPropertyEditor.cs
- ApplicationException.cs
- WorkflowViewElement.cs
- MetaColumn.cs
- NaturalLanguageHyphenator.cs
- ConnectionStringsExpressionEditor.cs
- ApplicationFileParser.cs
- TreeNodeCollection.cs
- _NegoState.cs
- SmtpSection.cs
- ChangePassword.cs
- PasswordTextContainer.cs
- SourceChangedEventArgs.cs
- XsdValidatingReader.cs
- _NestedMultipleAsyncResult.cs
- NativeRecognizer.cs
- DispatcherObject.cs
- AndAlso.cs
- httpapplicationstate.cs
- Table.cs
- OleDbDataAdapter.cs
- IDispatchConstantAttribute.cs
- CompilerState.cs
- CommunicationObjectAbortedException.cs