<commit_before>using System;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;

namespace Microsoft.Extensions.Caching.Distributed
{
    public static class DistributeCacheExtensions
    {
        public static Task SetObjectAsync(this IDistributedCache cache, string key, object obj)
        {
            return cache.SetAsync(key, Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(obj)));
        }

        public static void SetObject(this IDistributedCache cache, string key, object obj)
        {
            cache.Set(key, Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(obj)));
        }

        public static async Task<T> GetObjectAsync<T>(this IDistributedCache cache, string key) where T : class
        {
            var bytes = await cache.GetAsync(key).ConfigureAwait(false);

            if (bytes == null)
            {
                throw new ArgumentException("Key not found in cache");
            }

            return JsonConvert.DeserializeObject<T>(Encoding.UTF8.GetString(bytes));
        }

        public static T GetObject<T>(this IDistributedCache cache, string key) where T : class
        {
            var bytes = cache.Get(key);

            if (bytes == null)
            {
                throw new ArgumentException("Key not found in cache");
            }

            return JsonConvert.DeserializeObject<T>(Encoding.UTF8.GetString(bytes));
        }
    }
}<commit_msg>More IDistributedCache extensions<commit_after>using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;

namespace Microsoft.Extensions.Caching.Distributed
{
    public static class DistributeCacheExtensions
    {
        public static Task SetObjectAsync(this IDistributedCache cache, string key, object obj)
        {
            return cache.SetAsync(key, Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(obj)));
        }

        public static void SetObject(this IDistributedCache cache, string key, object obj)
        {
            cache.Set(key, Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(obj)));
        }

        public static async Task<T> GetObjectAsync<T>(this IDistributedCache cache, string key) where T : class
        {
            var bytes = await cache.GetAsync(key).ConfigureAwait(false);

            if (bytes == null) return null;

            return JsonConvert.DeserializeObject<T>(Encoding.UTF8.GetString(bytes));
        }

        public static T GetObject<T>(this IDistributedCache cache, string key) where T : class
        {
            var bytes = cache.Get(key);

            if (bytes == null) return null;

            return JsonConvert.DeserializeObject<T>(Encoding.UTF8.GetString(bytes));
        }

        public static async Task<object> GetObjectAsync(this IDistributedCache cache, string key)
        {
            var bytes = await cache.GetAsync(key).ConfigureAwait(false);

            if (bytes == null) return null;

            return JsonConvert.DeserializeObject(Encoding.UTF8.GetString(bytes));
        }

        public static object GetObject(this IDistributedCache cache, string key)
        {
            var bytes = cache.Get(key);

            if (bytes == null) return null;

            return JsonConvert.DeserializeObject(Encoding.UTF8.GetString(bytes));
        }

        public static async Task AddObjectToCollectionAsync<T>(this IDistributedCache cache, string key, T obj) where T : class
        {
            var collection = await cache.GetObjectAsync<HashSet<T>>(key).ConfigureAwait(false);

            if (collection == null)
            {
                await cache.SetObjectAsync(key, new HashSet<T> { obj }).ConfigureAwait(false);
            }
            else
            {
                collection.Add(obj);
                await cache.SetObjectAsync(key, collection).ConfigureAwait(false);
            }
        }

        public static void AddObjectToCollection<T>(this IDistributedCache cache, string key, T obj) where T : class
        {
            var collection = cache.GetObject<HashSet<T>>(key);

            if (collection == null)
            {
                cache.SetObject(key, new HashSet<T> { obj });
            }
            else
            {
                collection.Add(obj);
                cache.SetObject(key, collection);
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.0897670169026953, 'fraction_numerical': 0.0022841480127912287, 'mean_word_length': 2.2174871418074944, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 22, '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': '136643', 'n_tokens_mistral': 1124, 'n_tokens_neox': 1117, 'n_words': 277}