public void Dispose() { // Evict us out of the cache. We already know that cache entry is going to be expired: any further calls on the WeakReference would give nothing, // but we don't want to be holding onto the key either. _cache.Evict(Key); // Dispose the underlying value Value.Dispose(); }
private void StopTrackingRuleSetFile(RuleSetFile ruleSetFile) { // We can arrive here in one of two situations: // // 1. The underlying RuleSetFile was disposed by all consumers, and we can try cleaning up our weak reference. This is purely an optimization // to avoid the key/value pair being unnecessarily held. // 2. The RuleSetFile was modified, and we want to get rid of our cache now. Anybody still holding onto the values will dispose at their leaisure, // but it won't really matter anyways since the Dispose() that cleans up file trackers is already done. // // In either case, we can just be lazy and remove the key/value pair. It's possible in the mean time that the rule set had already been removed // (perhaps by a file change), and we're removing a live instance. This is fine, as this doesn't affect correctness: we consider this to be a cache // and if two callers got different copies that's fine. We *could* fetch the item out of the dictionary, check if the item is strong and then compare, // but that seems overkill. _ruleSetFileMap.Evict(ruleSetFile.FilePath); }