<commit_before>using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
using StructureMap.Building;

namespace StructureMap.Pipeline
{
    public class LifecycleObjectCache : IObjectCache
    {
        private readonly ReaderWriterLockSlim _lock;
        private readonly IDictionary<int, object> _objects = new Dictionary<int, object>();

        public LifecycleObjectCache()
        {
            _lock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
        }

        public int Count
        {
            get { return _lock.Read(() => _objects.Count); }
        }

        public bool Has(Type pluginType, Instance instance)
        {
            return _lock.Read(() => {
                var key = instance.InstanceKey(pluginType);
                return _objects.ContainsKey(key);
            });
        }

        public void Eject(Type pluginType, Instance instance)
        {
            var key = instance.InstanceKey(pluginType);
            _lock.MaybeWrite(() => {
                if (!_objects.ContainsKey(key)) return;

                _lock.Write(() => {<commit_msg>Prevent null reference exception during Dispose.<commit_after>using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
using StructureMap.Building;

namespace StructureMap.Pipeline
{
    public class LifecycleObjectCache : IObjectCache
    {
        private readonly ReaderWriterLockSlim _lock;
        private readonly IDictionary<int, object> _objects = new Dictionary<int, object>();

        public LifecycleObjectCache()
        {
            _lock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
        }

        public int Count
        {
            get { return _lock.Read(() => _objects.Count); }
        }

        public bool Has(Type pluginType, Instance instance)
        {
            return _lock.Read(() => {
                var key = instance.InstanceKey(pluginType);
                return _objects.ContainsKey(key);
            });
        }

        public void Eject(Type pluginType, Instance instance)
        {
            // Prevent null reference exception.
            if (pluginType.AssemblyQualifiedName == null)
                return;

            var key = instance.InstanceKey(pluginType);
            _lock.MaybeWrite(() => {
                if (!_objects.ContainsKey(key)) return;

                _lock.Write(() => {
{'fraction_non_alphanumeric': 0.08858187728565624, 'fraction_numerical': 0.0, 'mean_word_length': 2.1483375959079285, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2888480', 'n_tokens_mistral': 629, 'n_tokens_neox': 601, 'n_words': 147}