Example #1
0
        public async Task GettingContentMakesItStayLongerDecreasingRate()
        {
            using (var fileCollection = new InMemoryFileCollection())
            {
                const int cacheCapacity = 50000;
                using (var cache = new DiskChunkCache(fileCollection, 20, cacheCapacity))
                {
                    for (var i = 0; i < 80; i++)
                    {
                        Put(cache, i);
                        for (var j = 0; j < 79 - i; j++)
                        {
                            Get(cache, i);
                        }
                        if (CalcLength(fileCollection) <= cacheCapacity)
                        {
                            continue;
                        }
                        await FinishCompactTask(cache);

                        Assert.True(CalcLength(fileCollection) <= cacheCapacity);
                    }
                    _output.WriteLine(cache.CalcStats());
                    Assert.True(Get(cache, 0));
                    Assert.False(Get(cache, 60));
                }
            }
        }
Example #2
0
 public void AccessEveryTenthTenTimesMoreMakesItStay()
 {
     using (var fileCollection = new InMemoryFileCollection())
     {
         const int cacheCapacity = 50000;
         using (var cache = new DiskChunkCache(fileCollection, 20, cacheCapacity))
         {
             for (var i = 0; i < 46; i++)
             {
                 Put(cache, i);
                 for (var j = 0; j < (i % 5 == 0 ? 10 + i : 1); j++)
                 {
                     Get(cache, i);
                 }
                 if (i == 42)
                 {
                     Thread.Sleep(500);
                 }
                 Assert.True(fileCollection.Enumerate().Sum(f => (long)f.GetSize()) <= cacheCapacity);
             }
             _output.WriteLine(cache.CalcStats());
             Assert.True(Get(cache, 0));
             Assert.False(Get(cache, 1));
         }
     }
 }
Example #3
0
 public void GettingContentMakesItStayLongerDecreasingRate()
 {
     using (var fileCollection = new InMemoryFileCollection())
     {
         const int cacheCapacity = 50000;
         using (var cache = new DiskChunkCache(fileCollection, 20, cacheCapacity))
         {
             for (var i = 0; i < 80; i++)
             {
                 Put(cache, i);
                 for (var j = 0; j < 79 - i; j++)
                 {
                     Get(cache, i);
                 }
                 Assert.True(fileCollection.Enumerate().Sum(f => (long)f.GetSize()) <= cacheCapacity);
             }
             Console.WriteLine(cache.CalcStats());
             Assert.True(Get(cache, 0));
             Assert.False(Get(cache, 60));
         }
     }
 }