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
- OleStrCAMarshaler.cs
- UrlMappingCollection.cs
- XslAstAnalyzer.cs
- Geometry3D.cs
- x509utils.cs
- NotifyParentPropertyAttribute.cs
- ListBoxItemAutomationPeer.cs
- Int64.cs
- TagNameToTypeMapper.cs
- objectquery_tresulttype.cs
- BeginStoryboard.cs
- RectAnimationBase.cs
- HitTestWithPointDrawingContextWalker.cs
- StructureChangedEventArgs.cs
- WebPartTracker.cs
- WarningException.cs
- GridLengthConverter.cs
- DrawingImage.cs
- SoapAttributeAttribute.cs
- WebPageTraceListener.cs
- ChannelManagerBase.cs
- SoapSchemaExporter.cs
- RequestCachePolicy.cs
- OutputCacheModule.cs
- EntityDataSource.cs
- StringInfo.cs
- TimeStampChecker.cs
- QilPatternFactory.cs
- TemplateControlBuildProvider.cs
- XmlSerializerSection.cs
- RTLAwareMessageBox.cs
- TextSearch.cs
- SurrogateEncoder.cs
- TabRenderer.cs
- ComponentCollection.cs
- AutoGeneratedField.cs
- ScriptServiceAttribute.cs
- WindowsSspiNegotiation.cs
- ValidationSummary.cs
- DesignerSelectionListAdapter.cs
- Property.cs
- SQLInt16Storage.cs
- RuleElement.cs
- WindowsListViewGroup.cs
- DelegateHelpers.cs
- RectAnimation.cs
- DefaultCommandConverter.cs
- GeneralTransform2DTo3DTo2D.cs
- DataList.cs
- StringBuilder.cs
- QueryOptionExpression.cs
- FacetChecker.cs
- ColorEditor.cs
- PointAnimationUsingPath.cs
- MessageVersionConverter.cs
- XmlSignatureManifest.cs
- ParagraphVisual.cs
- ApplicationManager.cs
- ToolBar.cs
- TypePropertyEditor.cs
- Quaternion.cs
- FacetDescription.cs
- ProviderBase.cs
- SHA256.cs
- PrinterResolution.cs
- SafeProcessHandle.cs
- LambdaCompiler.Lambda.cs
- HtmlTableRowCollection.cs
- ActivityDelegate.cs
- Model3DCollection.cs
- StandardCommands.cs
- DisableDpiAwarenessAttribute.cs
- TextTreeExtractElementUndoUnit.cs
- DataSourceSelectArguments.cs
- SqlInternalConnectionSmi.cs
- CreateParams.cs
- StorageMappingItemLoader.cs
- EdmItemError.cs
- CodeMemberProperty.cs
- Font.cs
- WithParamAction.cs
- Object.cs
- AssociationTypeEmitter.cs
- InfoCardSymmetricAlgorithm.cs
- WebPartConnection.cs
- PolygonHotSpot.cs
- CSharpCodeProvider.cs
- TextTreeUndoUnit.cs
- UInt64Storage.cs
- PhysicalAddress.cs
- SHA512Managed.cs
- StylusPointPropertyInfoDefaults.cs
- InputBuffer.cs
- PeerNameResolver.cs
- LayoutEditorPart.cs
- XpsFixedPageReaderWriter.cs
- SchemaType.cs
- PanningMessageFilter.cs
- MimeBasePart.cs
- DtdParser.cs