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
- Component.cs
- QueryOutputWriter.cs
- WebBrowserBase.cs
- MouseEventArgs.cs
- ObjectDataSourceSelectingEventArgs.cs
- compensatingcollection.cs
- MemoryStream.cs
- WrappedIUnknown.cs
- PrintPreviewDialog.cs
- WebContext.cs
- SapiRecognizer.cs
- _ShellExpression.cs
- Rect.cs
- UpdatePanelTrigger.cs
- ReadOnlyTernaryTree.cs
- InkCanvasFeedbackAdorner.cs
- precedingquery.cs
- Material.cs
- Duration.cs
- Stack.cs
- XPathNode.cs
- NavigationCommands.cs
- RequestResizeEvent.cs
- SafeEventLogWriteHandle.cs
- PasswordBox.cs
- ExceptionUtility.cs
- PropertyFilterAttribute.cs
- Inflater.cs
- MultipartContentParser.cs
- ComponentConverter.cs
- VerticalAlignConverter.cs
- ServicePointManagerElement.cs
- ObjectAssociationEndMapping.cs
- AspNetSynchronizationContext.cs
- ClassHandlersStore.cs
- ZipIOFileItemStream.cs
- AndCondition.cs
- ProcessHostFactoryHelper.cs
- NamespaceDisplayAutomationPeer.cs
- PointAnimationUsingKeyFrames.cs
- _ContextAwareResult.cs
- Figure.cs
- VirtualPathUtility.cs
- TextBoxLine.cs
- LabelLiteral.cs
- RTTypeWrapper.cs
- DataSourceGeneratorException.cs
- TextEditorThreadLocalStore.cs
- SmtpReplyReaderFactory.cs
- listitem.cs
- FixedPageProcessor.cs
- ListViewItem.cs
- UiaCoreTypesApi.cs
- ListBoxChrome.cs
- GenericXmlSecurityToken.cs
- DBConcurrencyException.cs
- Util.cs
- CutCopyPasteHelper.cs
- ToolZone.cs
- RowsCopiedEventArgs.cs
- MatcherBuilder.cs
- COM2PropertyBuilderUITypeEditor.cs
- EntityUtil.cs
- NavigatingCancelEventArgs.cs
- CssTextWriter.cs
- LocalizationParserHooks.cs
- DataColumnPropertyDescriptor.cs
- GeneralTransform3DTo2D.cs
- ListBoxAutomationPeer.cs
- EntityDataSourceViewSchema.cs
- NumberFunctions.cs
- SoapBinding.cs
- PromptEventArgs.cs
- FormatConvertedBitmap.cs
- FilteredDataSetHelper.cs
- CommandHelpers.cs
- InertiaExpansionBehavior.cs
- InternalsVisibleToAttribute.cs
- SingleKeyFrameCollection.cs
- AsmxEndpointPickerExtension.cs
- BCryptHashAlgorithm.cs
- CodeNamespaceImportCollection.cs
- SignatureGenerator.cs
- NativeMethods.cs
- CompositeCollection.cs
- GiveFeedbackEventArgs.cs
- VScrollProperties.cs
- ReflectPropertyDescriptor.cs
- XPathMultyIterator.cs
- TextTreeTextElementNode.cs
- FilterableAttribute.cs
- ResponseStream.cs
- SafeCryptContextHandle.cs
- DebugInfoExpression.cs
- BitStack.cs
- WebPartExportVerb.cs
- ClassImporter.cs
- SearchForVirtualItemEventArgs.cs
- TextRangeEdit.cs
- ZeroOpNode.cs