<commit_before>﻿namespace Uncas.Core.Web
{
    using System;
    using System.Diagnostics.CodeAnalysis;
    using System.Web;
    using System.Web.Caching;

    /// <summary>
    /// Cache helper.
    /// </summary>
    public class CacheHelper
    {
        private const double CacheDuration = 60.0 * 5.0;

        private string[] MasterCacheKeyArray = { string.Empty };

        /// <summary>
        /// Initializes a new instance of the <see cref="CacheHelper"/> class.
        /// </summary>
        /// <param name="masterCacheKey">The master cache key.</param>
        public CacheHelper(string masterCacheKey)
        {
            MasterCacheKeyArray = new string[1] { masterCacheKey };
        }

        /// <summary>
        /// Gets the cache item.
        /// </summary>
        /// <param name="rawKey">The raw key.</param>
        /// <returns></returns>
        public object GetCacheItem(string rawKey)
        {
            return HttpRuntime.Cache[GetCacheKey(rawKey)];
        }

        /// <summary>
        /// Adds the cache item.
        /// </summary>
        /// <param name="rawKey">The raw key.</param>
        /// <param name="value">The value.</param>
        [SuppressMessage(
            "Microsoft.Reliability", 
            "CA2000:Dispose objects before losing scope")]
        public void AddCacheItem(string rawKey, object value)
        {
            if (value == null)
            {
                return;
            }

            Cache dataCache = HttpRuntime.Cache;

            // Make sure MasterCacheKeyArray[0] is in the cache - if not, add it.
            if (dataCache[MasterCacheKeyArray[0]] == null)
            {
                dataCache[MasterCacheKeyArray[0]] = DateTime.UtcNow;
            }

            // TODO: Test what happens if I dispose this cache dependency after inserting in cache.
            // Adding a cache dependency:
            var dependency =
                new CacheDependency(null, MasterCacheKeyArray);
            dataCache.Insert(
                GetCacheKey(rawKey), 
                value, 
                dependency,
                DateTime.UtcNow.AddSeconds(CacheDuration),
                Cache.NoSlidingExpiration);
        }

        /// <summary>
        /// Invalidates the cache.
        /// </summary>
        public void InvalidateCache()
        {
            // Remove the cache dependency 
            HttpRuntime.Cache.Remove(MasterCacheKeyArray[0]);
        }

        private string GetCacheKey(string rawKey)
        {
            return string.Concat(MasterCacheKeyArray[0], "-", rawKey);
        }
    }
}<commit_msg>Providing justification for suppression.<commit_after>﻿namespace Uncas.Core.Web
{
    using System;
    using System.Diagnostics.CodeAnalysis;
    using System.Web;
    using System.Web.Caching;

    /// <summary>
    /// Cache helper.
    /// </summary>
    public class CacheHelper
    {
        private const double CacheDuration = 60.0 * 5.0;

        private string[] MasterCacheKeyArray = { string.Empty };

        /// <summary>
        /// Initializes a new instance of the <see cref="CacheHelper"/> class.
        /// </summary>
        /// <param name="masterCacheKey">The master cache key.</param>
        public CacheHelper(string masterCacheKey)
        {
            MasterCacheKeyArray = new string[1] { masterCacheKey };
        }

        /// <summary>
        /// Gets the cache item.
        /// </summary>
        /// <param name="rawKey">The raw key.</param>
        /// <returns></returns>
        public object GetCacheItem(string rawKey)
        {
            return HttpRuntime.Cache[GetCacheKey(rawKey)];
        }

        /// <summary>
        /// Adds the cache item.
        /// </summary>
        /// <param name="rawKey">The raw key.</param>
        /// <param name="value">The value.</param>
        [SuppressMessage(
            "Microsoft.Reliability",
            "CA2000:Dispose objects before losing scope",
            Justification = "The cache dependency is stored in cache.")]
        public void AddCacheItem(string rawKey, object value)
        {
            if (value == null)
            {
                return;
            }

            Cache dataCache = HttpRuntime.Cache;

            // Make sure MasterCacheKeyArray[0] is in the cache - if not, add it.
            if (dataCache[MasterCacheKeyArray[0]] == null)
            {
                dataCache[MasterCacheKeyArray[0]] = DateTime.UtcNow;
            }

            // TODO: Test what happens if I dispose this cache dependency after inserting in cache.
            // Adding a cache dependency:
            var dependency =
                new CacheDependency(null, MasterCacheKeyArray);
            dataCache.Insert(
                GetCacheKey(rawKey),
                value,
                dependency,
                DateTime.UtcNow.AddSeconds(CacheDuration),
                Cache.NoSlidingExpiration);
        }

        /// <summary>
        /// Invalidates the cache.
        /// </summary>
        public void InvalidateCache()
        {
            // Remove the cache dependency 
            HttpRuntime.Cache.Remove(MasterCacheKeyArray[0]);
        }

        private string GetCacheKey(string rawKey)
        {
            return string.Concat(MasterCacheKeyArray[0], "-", rawKey);
        }
    }
}
{'fraction_non_alphanumeric': 0.11061285500747384, 'fraction_numerical': 0.005605381165919282, 'mean_word_length': 1.5834942084942085, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 45, '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': '7129502', 'n_tokens_mistral': 1393, 'n_tokens_neox': 1332, 'n_words': 341}