<commit_before>﻿using System;
using Xunit;
using FCP.Cache.Memory;
using System.Threading;
using System.Collections.Generic;
using System.Linq;

namespace FCP.Cache.Test
{
    public class MemoryCacheTest
    {
        [Fact]
        public void MemoryCache_Absolute_Expire()
        {
            var key = Guid.NewGuid().ToString("N");
            var options = CacheEntryOptionsFactory.AbSolute().Timeout(TimeSpan.FromMilliseconds(300));

            var memoryCache = MemoryCacheProvider.Default;
            memoryCache.Set(key, "something", options);

            Assert.Equal("something", memoryCache.Get<string>(key));

            Thread.Sleep(300);

            Assert.Null(memoryCache.Get<string>(key));
        }

        [Fact]
        public void MemoryCache_Sliding_Expire()
        {
            var memoryCache = MemoryCacheProvider.Default;

            var key = Guid.NewGuid().ToString("N");
            var options = CacheEntryOptionsFactory.Sliding().Timeout(TimeSpan.FromMilliseconds(100));
            memoryCache.Set(key, "something", options);            

            Thread.Sleep(80);
            Assert.Equal("something", memoryCache.Get<string>(key));

            Thread.Sleep(80);
            Assert.Equal("something", memoryCache.Get<string>(key));

            Thread.Sleep(100);
            Assert.Null(memoryCache.Get<string>(key));

            options = CacheEntryOptionsFactory.Sliding().Timeout(TimeSpan.FromSeconds(2));
            memoryCache.Set(key, "something", options);

            Thread.Sleep(1800);
            Assert.Equal("something", memoryCache.Get<string>(key));

            Thread.Sleep(1800);
            Assert.Equal("something", memoryCache.Get<string>(key));<commit_msg>adjust memorycache sliding expire timeout<commit_after>﻿using System;
using Xunit;
using FCP.Cache.Memory;
using System.Threading;
using System.Collections.Generic;
using System.Linq;

namespace FCP.Cache.Test
{
    public class MemoryCacheTest
    {
        [Fact]
        public void MemoryCache_Absolute_Expire()
        {
            var key = Guid.NewGuid().ToString("N");
            var options = CacheEntryOptionsFactory.AbSolute().Timeout(TimeSpan.FromMilliseconds(300));

            var memoryCache = MemoryCacheProvider.Default;
            memoryCache.Set(key, "something", options);

            Assert.Equal("something", memoryCache.Get<string>(key));

            Thread.Sleep(300);

            Assert.Null(memoryCache.Get<string>(key));
        }

        [Fact]
        public void MemoryCache_Sliding_Expire()
        {
            var memoryCache = MemoryCacheProvider.Default;

            var key = Guid.NewGuid().ToString("N");
            var options = CacheEntryOptionsFactory.Sliding().Timeout(TimeSpan.FromMilliseconds(300));
            memoryCache.Set(key, "something", options);            

            Thread.Sleep(250);
            Assert.Equal("something", memoryCache.Get<string>(key));

            Thread.Sleep(250);
            Assert.Equal("something", memoryCache.Get<string>(key));

            Thread.Sleep(100);
            Assert.Null(memoryCache.Get<string>(key));

            options = CacheEntryOptionsFactory.Sliding().Timeout(TimeSpan.FromSeconds(2));
            memoryCache.Set(key, "something", options);

            Thread.Sleep(1800);
            Assert.Equal("something", memoryCache.Get<string>(key));

            Thread.Sleep(1800);
            Assert.Equal("something", memoryCache.Get<string>(key));
{'fraction_non_alphanumeric': 0.12364052661705781, 'fraction_numerical': 0.014882655981682884, 'mean_word_length': 2.5196374622356497, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '4802230', 'n_tokens_mistral': 961, 'n_tokens_neox': 889, 'n_words': 147}