public void AddOrAccess(SyntaxNode instance, IWeakAction<SyntaxNode> evictor) { if (!trees.ContainsKey(instance)) { trees[instance] = evictor; } }
public void AddOrAccess(SyntaxNode instance, IWeakAction <SyntaxNode> evictor) { if (!trees.ContainsKey(instance)) { trees[instance] = evictor; } }
public void AddOrAccess(T item, IWeakAction <T> evictor) { Contract.ThrowIfNull(evictor); // move up cost upper bound by fixed increase amount. Interlocked.Add(ref this.currentCostUpperBound, this.fixedIncrementAmount); // check whether it already exist. we do this here since we don't want to // create new CacheEntry unnecessarily CacheEntry existingEntry; var existed = this.items.TryGetValue(item, out existingEntry); // cache miss if (!existed) { // try add - could have been added by other threads var newCacheEntry = new CacheEntry(CacheId.NextItemId(), evictor); existingEntry = this.items.AddOrUpdate(item, newCacheEntry, updateCacheEntry); // it was already cached by other thread existed = newCacheEntry != existingEntry; } else { // there is a race here. entry might have been kicked out from the cache and we are changing a // stale one. the race could introduce a situation where an item that has been chosen for eviction by one thread // is being accessed here. that's unfortunate, but I feel it's acceptable. UpdateCacheEntry(item, existingEntry); } CreateEvictionTaskIfNecessary(); Logger.Log(FeatureId.Cache, FunctionId.Cache_AddOrAccess, logAddOrAccessed, existingEntry.ItemId, item, existed); }
public AbstractRecoverableSyntaxRoot( AbstractSyntaxTreeFactoryService service, string filePath, ParseOptions options, ValueSource <TextAndVersion> text, TRoot root) { System.Diagnostics.Debug.Assert(service != null); System.Diagnostics.Debug.Assert(filePath != null); System.Diagnostics.Debug.Assert(options != null); System.Diagnostics.Debug.Assert(text != null); System.Diagnostics.Debug.Assert(root != null); this.service = service; this.filePath = filePath; this.options = options; this.textSource = text; this.length = root.FullSpan.Length; this.syntaxTreeCache = WorkspaceServices.GetService <ISyntaxTreeCacheService>(); System.Diagnostics.Debug.Assert(this.syntaxTreeCache != null); this.evictAction = new WeakAction <AbstractRecoverableSyntaxRoot <TRoot>, SyntaxNode>(this, (r, d) => r.OnEvicted(d)); this.rootSource = new ConstantValueSource <TRoot>(root); }
public RecoverableCachedObjectSource(ValueSource <T> initialValue, IObjectCache <T> cache) { this.weakInstance = NoReference; this.recoverySource = initialValue; this.cache = cache; this.evictAction = new WeakAction <RecoverableCachedObjectSource <T>, T>(this, (o, d) => o.OnEvicted(d)); }
public CachedObjectSource(T instance, IObjectCache <T> cache) { this.weakInstance = new WeakReference <T>(instance); this.cache = cache; this.evictAction = new WeakAction <CachedObjectSource <T>, T>(this, (o, d) => o.OnEvicted(d)); cache.AddOrAccess(instance, this.evictAction); }
public CacheEntry(long itemId, IWeakAction <T> evictor) { this.ItemId = itemId; this.CreatedTime = Environment.TickCount; this.EvictAction = evictor; this.LastTimeAccessed = DateTime.UtcNow; this.AccessCount = 1; this.Cost = UnitializedCost; }
/// <summary> /// Initializes a new instance of the <see cref="EventBinding"/> class. /// </summary> /// <param name="event">The event bound.</param> /// <param name="action">The weak action to perform for the event.</param> public EventBinding(Event @event, IWeakAction <ReceivedEvent> action) { if (string.IsNullOrEmpty(@event.SourceName) || string.IsNullOrEmpty(@event.TargetMethodName)) { throw new ArgumentOutOfRangeException(nameof(@event), "The event provided must specify a source entity name and provide a non-empty target method name."); } Event = @event; Action = action; }
/// <summary> /// Determines whether the handler and the weak action are equal. /// </summary> /// <typeparam name="TMessage">The type of the message.</typeparam> /// <param name="handler">The handler to compare to the weak action.</param> /// <param name="weakAction">The weak action to compare to the handler.</param> /// <returns><c>true</c> if the handlers are equal; otherwise <c>false</c>.</returns> /// <exception cref="ArgumentNullException">The <paramref name="handler"/> is <c>null</c></exception> /// <exception cref="ArgumentNullException">The <paramref name="weakAction"/> is <c>null</c></exception> private bool AreEqualHandlers <TMessage>(Action <TMessage> handler, IWeakAction <TMessage> weakAction) { Argument.IsNotNull("handler", handler); Argument.IsNotNull("weakAction", weakAction); #if NETFX_CORE || PCL return(weakAction.Action == (Delegate)handler); #else var handlerMethod = handler.Method.ToString(); return(string.CompareOrdinal(weakAction.MethodName, handlerMethod) == 0); #endif }
protected CachedRecoverableSyntaxRoot( AbstractSyntaxTreeFactoryService service, string filePath, ParseOptions options, ValueSource <TextAndVersion> textSource, ValueSource <TRoot> rootSource, int length) : base(service, filePath, options, textSource) { this.rootSource = rootSource; this.length = length; this.syntaxTreeCache = service.languageServices.WorkspaceServices.GetService <ISyntaxTreeCacheService>(); this.evictAction = new WeakAction <CachedRecoverableSyntaxRoot <TRoot>, SyntaxNode>(this, (r, d) => r.OnEvicted(d)); }
///------------------------------------------------------------------------------------------------- /// <summary> /// Sends a message to registered recipients. The message will reach all recipients that /// registered for this message type. /// </summary> /// /// <typeparam name="TMessage"> /// The type of message that will be sent. /// </typeparam> /// <param name="topicID"> /// Topic Unique identifier. /// </param> /// <param name="message"> /// The message to send to registered recipients. /// </param> ///------------------------------------------------------------------------------------------------- public void Publish <TMessage>(string topicID, TMessage message) { if (topicsDictionary.ContainsKey(topicID)) { foreach (var reciepent in topicsDictionary[topicID].Reciepents) { try { IWeakAction <TMessage> action = reciepent.Value as IWeakAction <TMessage>; if (action != null) { action.Execute(message); } } catch (Exception) { } } } }
public void AddOrAccess(Compilation instance, IWeakAction<Compilation> evictor) { evictor.Invoke(instance); }
public void AddOrAccess(TextAndVersion instance, IWeakAction<TextAndVersion> evictor) { evictor.Invoke(instance); }
public void AddOrAccess(SyntaxNode instance, IWeakAction<SyntaxNode> evictor) { evictor.Invoke(instance); }
public void AddOrAccess(TextAndVersion instance, IWeakAction <TextAndVersion> evictor) { evictor.Invoke(instance); }
public void AddOrAccess(SyntaxNode instance, IWeakAction <SyntaxNode> evictor) { evictor.Invoke(instance); }
public void AddOrAccess(Compilation instance, IWeakAction <Compilation> evictor) { evictor.Invoke(instance); }