/// <summary> /// Lookup an item from the metadata cache for a given service type. /// </summary> /// <param name="serviceType">Service type for which we want to lookup metadata.</param> /// <returns>MetadataCacheItem for the service type. Null if there is no item in the cache for the given service type.</returns> internal static MetadataCacheItem TryLookup(Type serviceType) { MetadataCacheItem item; var key = new MetadataCacheKey(serviceType); _cache.TryGetValue(key, out item); return(item); }
/// <summary> /// Add an MetadataCacheItem object to the cache for a given service. /// </summary> /// <param name="serviceType">Type of the service class</param> /// <param name="item">Item to be added to the cache</param> /// <returns>Item that was added to the cache</returns> internal static MetadataCacheItem AddCacheItem(Type serviceType, MetadataCacheItem item) { MetadataCacheItem item2; var key = new MetadataCacheKey(serviceType); // Use a double check lock for concurrency. if (!_cache.TryGetValue(key, out item2)) { lock (_lockObject) { if (!_cache.TryGetValue(key, out item2)) { _cache.Add(key, item); item2 = item; } } } return(item2); }