<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Joe.Caching
{
    public class Cache
    {
        public static ICacheProvider<int, Object> CacheProvider { get; set; }
        private static Cache _instance;
        private IDictionary<String, CacheHandle> _delegates = new Dictionary<String, CacheHandle>();
        public static Cache Instance
        {
            get
            {
                _instance = _instance ?? new Cache();
                return _instance;
            }
        }

        public void Add(String key, TimeSpan duration, Delegate handle)
        {
            if (_delegates.ContainsKey(key))
                throw new Exception("Cache already contains an entry for the given key");

            _delegates.Add(key, new CacheHandle(handle, duration, CacheProvider));
        }

        public void Remove(String key)
        {
            _delegates.Remove(key);
        }

        public void Flush(String key)
        {
            if (_delegates.ContainsKey(key))
                _delegates[key].Flush();
        }

        public void Flush()
        {
            foreach (var cacheHandle in _delegates)
                cacheHandle.Value.Flush();
        }

        public void Clear()
        {
            _delegates.Clear();
        }<commit_msg>Adding ability to overwrite already added cached entry<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Joe.Caching
{
    public class Cache
    {
        public static ICacheProvider<int, Object> CacheProvider { get; set; }
        private static Cache _instance;
        private IDictionary<String, CacheHandle> _delegates = new Dictionary<String, CacheHandle>();
        public static Cache Instance
        {
            get
            {
                _instance = _instance ?? new Cache();
                return _instance;
            }
        }

        public void Add(String key, TimeSpan duration, Delegate handle, Boolean overwrite)
        {
            //if (_delegates.ContainsKey(key))
            //    

            //Overwrite Delegate
            if (_delegates.ContainsKey(key))
                if (overwrite)
                    _delegates.Remove(key);
                else
                    throw new Exception("Cache already contains an entry for the given key");

            _delegates.Add(key, new CacheHandle(handle, duration, CacheProvider));
        }

        public void Add(String key, TimeSpan duration, Delegate handle)
        {
            Add(key, duration, handle, true);
        }

        public void Remove(String key)
        {
            _delegates.Remove(key);
        }

        public void Flush(String key)
        {
            if (_delegates.ContainsKey(key))
                _delegates[key].Flush();
        }

        public void Flush()
        {
            foreach (var cacheHandle in _delegates)
                cacheHandle.Value.Flush();
        }

        public void Clear()
        {
            _delegates.Clear();
        }
{'fraction_non_alphanumeric': 0.08151658767772511, 'fraction_numerical': 0.0, 'mean_word_length': 1.6898895497026338, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '2024032', 'n_tokens_mistral': 798, 'n_tokens_neox': 786, 'n_words': 219}