<commit_before>﻿namespace AgileObjects.AgileMapper.Caching
{
    using System;
    using System.Collections.Generic;

    internal class DictionaryCache : ICache
    {
        private readonly Dictionary<object, object> _items;

        public DictionaryCache()
        {
            _items = new Dictionary<object, object>();
        }

        public TValue GetOrAdd<TKey, TValue>(TKey key, Func<TKey, TValue> valueFactory)
        {
            object value;

            if (!_items.TryGetValue(key, out value))
            {
                lock (_items)
                {
                    if (!_items.TryGetValue(key, out value))
                    {
                        _items.Add(key, (value = valueFactory.Invoke(key)));
                    }
                }
            }

            return (TValue)value;
        }
    }
}<commit_msg>Tidying underlying dictionary access<commit_after>﻿namespace AgileObjects.AgileMapper.Caching
{
    using System;
    using System.Collections.Generic;

    internal class DictionaryCache : ICache
    {
        private readonly Dictionary<object, object> _items;

        public DictionaryCache()
        {
            _items = new Dictionary<object, object>();
        }

        public TValue GetOrAdd<TKey, TValue>(TKey key, Func<TKey, TValue> valueFactory)
        {
            object value;

            // ReSharper disable once InconsistentlySynchronizedField
            if (_items.TryGetValue(key, out value))
            {
                return (TValue)value;
            }

            lock (_items)
            {
                if (!_items.TryGetValue(key, out value))
                {
                    _items.Add(key, (value = valueFactory.Invoke(key)));
                }
            }

            return (TValue)value;
        }
    }
}
{'fraction_non_alphanumeric': 0.0881542699724518, 'fraction_numerical': 0.0, 'mean_word_length': 1.5082872928176796, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '6872514', 'n_tokens_mistral': 486, 'n_tokens_neox': 460, 'n_words': 101}