<commit_before>﻿using System;
using System.Security;
using Microsoft.ApplicationServer.Caching;

namespace NuGetGallery
{
    public class CloudCacheService : ICacheService
    {
        // The DataCacheFactory object is expensive.
        // It should be created only once per app domain.
        private DataCacheFactory _cacheFactory;

        public CloudCacheService(IConfiguration configuration)
        {
            DataCacheFactoryConfiguration cacheConfig = new DataCacheFactoryConfiguration();
            cacheConfig.Servers = new[] {
                new DataCacheServerEndpoint(configuration.AzureCacheEndpoint, 22233)
            };
            string keyRaw = configuration.AzureCacheKey;
            SecureString key = new SecureString();
            foreach (char c in keyRaw)
            {
                key.AppendChar(c);
            }
            key.MakeReadOnly();
            DataCacheSecurity security = new DataCacheSecurity(key);
            cacheConfig.SecurityProperties = security;

            _cacheFactory = new DataCacheFactory(cacheConfig);
        }

        public object GetItem(string key)
        {
            DataCache dataCache = _cacheFactory.GetDefaultCache();
            return dataCache.Get(key);
        }

        public void SetItem(string key, object item, TimeSpan timeout)
        {
            DataCache dataCache = _cacheFactory.GetDefaultCache();<commit_msg>Made data cache factory readonly in CloudCacheService<commit_after>﻿using System;
using System.Security;
using Microsoft.ApplicationServer.Caching;

namespace NuGetGallery
{
    public class CloudCacheService : ICacheService
    {
        // The DataCacheFactory object is expensive.
        // It should be created only once per app domain.
        private readonly DataCacheFactory _cacheFactory;

        public CloudCacheService(IConfiguration configuration)
        {
            DataCacheFactoryConfiguration cacheConfig = new DataCacheFactoryConfiguration();
            cacheConfig.Servers = new[] {
                new DataCacheServerEndpoint(configuration.AzureCacheEndpoint, 22233)
            };
            string keyRaw = configuration.AzureCacheKey;
            SecureString key = new SecureString();
            foreach (char c in keyRaw)
            {
                key.AppendChar(c);
            }
            key.MakeReadOnly();
            DataCacheSecurity security = new DataCacheSecurity(key);
            cacheConfig.SecurityProperties = security;

            _cacheFactory = new DataCacheFactory(cacheConfig);
        }

        public object GetItem(string key)
        {
            DataCache dataCache = _cacheFactory.GetDefaultCache();
            return dataCache.Get(key);
        }

        public void SetItem(string key, object item, TimeSpan timeout)
        {
            DataCache dataCache = _cacheFactory.GetDefaultCache();
{'fraction_non_alphanumeric': 0.06386671294689344, 'fraction_numerical': 0.003471017007983339, 'mean_word_length': 2.2675736961451247, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4995302', 'n_tokens_mistral': 667, 'n_tokens_neox': 645, 'n_words': 174}